Releasing memory

Tarby777

Member
Hi all,

1. A .p makes a call to a class file, like this:

Code:
IF012-SharePoint:GetSEFFolder(OUTPUT cSharepointStagingArea, OUTPUT cSEFFolderStatus).

The class and method are defined like this:

Code:
CLASS Interface.IF012-SharePoint FINAL:

    METHOD PUBLIC STATIC VOID GetSEFFolder (OUTPUT pcFolder AS CHARACTER, OUTPUT pcMessage AS CHARACTER):
    ...
    END METHOD.
    
END CLASS.

The method just reads a DB record with no-lock, it doesn't instantiate anything. I don't need to do anything in the calling .p to release memory after calling the class, do I?

2. A .p in WebSpeed unpacks the payload from an HTTP post like this:

Code:
DEF VAR mPhoto AS MEMPTR NO-UNDO.

DO iFileIndex = 0 to iFileCount - 1:

    cKey = SUBSTITUTE('file[]&1', iFileIndex).
    mPhoto = GET-BINARY-DATA(INPUT cKey).
    cFileName = 'Something.jpg'.
    
    COPY-LOB FROM mPhoto TO FILE cFileName NO-ERROR.
    
END.

FINALLY:
    SET-SIZE(mPhoto) = 0.
END.

It's OK to just release the memory from the memptr once at the end like this, isn't it?

I'm just looking to eliminate these two things as possible causes of a resource problem in WebSpeed in PASOE in 11.6 before I go diving in...

TIA
Tarby
 

peterjudge

Member
As @Cringer says, you should clean up on each iteration of the loop. Right now there are n - 1 blobs of memory leaking. That entails adding a ON ERROR UNDO, THROW phrase to the DO block and moving the FINALLY block inside the DO.

I would also be careful of buffer scope with the static method. Make sure you define a buffer scoped to the method.
 
Top