Garbage collection (crashing on Windows)

Monte Goulding monte at
Wed Aug 17 19:26:09 EDT 2016

There are certainly a number of tricks you can use to reduce the memory usage of your app. One interesting one I learnt recently after an internal discussion was because LiveCode copies values that have multiple reference when they are mutated and custom properties are arrays linked to the object you can save some memory by doing the following:

put the myProp of me into tVar
set the myProp of me to empty — here we are dereferencing the value so LiveCode doesn’t do a deep copy
MutateVar tVar
set the myProp of me to tVar

Obviously there’s also passing by reference etc to reduce copies.

The other thing you want to look at doing here is processing data in chunks rather than reading it all in.



> On 18 Aug 2016, at 3:52 AM, Ben Rubinstein <benr_mc at> wrote:
> Please refresh my memory: is there any way to cause/allow garbage to be collected without ending all script running?
> I have an app which process large amounts of data. It runs fine on Mac, but on Windows intermittently (but not frequently as the application data source, which fluctuates, is gradually increasing) as the total memory in use approaches 2GB, the app faults.
> Obviously this is very distressing for me and my client, because the app has lost control at this point and can't even tell us what's happening (it normally runs on a schedule on a VM, so it often takes days to discover that the system downstream hasn't been updated for a while, and trace back to find that the LC app is halted).
> I have managed to reduce the incidence of this by breaking the processing into two parts, but this is undesirable for various reasons, and only palliative. What I really want is a way for my main function to invoke garbage collection after calling some of the larger processing steps.
> Is there any way to do this? Am I right in thinking that the issue is related to LC's total memory usage reaching 2GB on Windows? Are there any useful functions (e.g. the "hasMemory" function is documented as "only partially implemented, and may not return useful values on some platforms", which makes it seem pretty pointless...)?

More information about the Use-livecode mailing list