Externals and Memory Leaks???
Dave
dave at looktowindward.com
Thu May 24 04:44:03 EDT 2007
Hi All,
I have a Stack that uses two functions from an external:
XGetData("myTempData")
XProcessData(myTempData,"myNewData")
XGetData() Gets the data into the correct format and stores it in the
RunRev variable "myTempData".
XProcessData() takes the data in "myTempData", processes it and puts
the results into "myNewData".
This all works well and produces good results, the only problem is
that memory seems to be leaking by quite a lot and the two data
buffers here are quite large.
In the external, I use malloc() to allocate the buffers and then use
"SetVariableEx()" to pass it back to RunRev. My question is, who is
responsible for freeing the data?
I am guessing that the on each subsequent call to the External
Functions causes a new block to be allocated and overwrites the
contents of the old RunRev "ExternalString" structure without first
freeing it. How should I handle this? Do I need to check if the
variable passed into my external already has data allocated and if so
either free or re-use the data (the block sizes are likely to be the
same).
Any advice or help on this greatly appreciated.
All the Best
Dave
PS
I set the External Variable using the following function:
OSStatus LTWLibraryUtilsSetExternalVariablePtr( char*
theVariableNamePtr,
const char* theVariablePtr,
long theVariableSize)
{
ExternalString myExternalVariableInfo;
int myRunRevStatus;
//**
//** Get the External Variable
//**
myExternalVariableInfo.buffer = theVariablePtr;
myExternalVariableInfo.length = theVariableSize;
SetVariableEx
(theVariableNamePtr,"",&myExternalVariableInfo,&myRunRevStatus);
if (myRunRevStatus == EXTERNAL_FAILURE)
return(kRunRevVariableNotDefined);
//**
//** Good Return
//**
return(noErr);
}
More information about the use-livecode
mailing list