GENERATE/PREV.gifGENERATE/NEXT.gif

Garbage Collection

The function gc() enables the garbage collector to be invoked. Normally, the collector runs automatically when available memory runs low, so you don't need to bother about it. In some situations, it is useful to be able to force a collect so that you can ensure that a pause due to garbage collection will be delayed as long as possible.

You can also invoke the collector to cause any dangling open files to be closed. In some situations, a file can be left open if a runtime error occurs while it is still open. If the file object was being held in a local variable at this point, there may be no way to get at it from the listener to force a close and any subsequent attempts to open it may result in an "already open" error from the operating system. Running the collector will cause the file object to be reclaimed and this forces any open file associated with it to be closed.

The function takes no arguments and is called as follows:

gc ()

It returns the number of bytes free in the MAXScript heap after collection. Note that the collector may take many seconds to run if the heap is full of many small reclaimable objects.