Garbage collection

The PocketBuilder garbage collection mechanism checks memory automatically for unreferenced and orphaned objects and removes any it finds, thus taking care of most memory leaks. You can use garbage collection to destroy objects instead of explicitly destroying them using the DESTROY statement. This lets you avoid runtime errors that occur when you destroy an object that was being used by another process or had been passed by reference to a posted event or function.

When garbage collection occurs

Garbage collection occurs:

Exceptions to garbage collection

There are a few objects that are not collected:

Controlling when garbage collection occurs

Garbage collection occurs automatically in PocketBuilder, but you can use functions to force immediate garbage collection or to change the interval between reference count checks. Three functions allow you to control when garbage collection occurs: GarbageCollect, GarbageCollectGetTimeLimit, and GarbageCollectSetTimeLimit.

For information about these functions, see the online Help.