Garbage collection is a form of automatic memory management that frees up the memory from objects not used by an application. Flash Lite frees unused memory by running a process called garbage collector (GC) once every 60 seconds or whenever usage of memory increases suddenly by 20% or more. Since this design takes care of most of the use cases, there is no need to kick-off the process explicitly via code. Hence, there is no API or command to do so.
Although you cannot control how and when Flash Lite performs
garbage collection, it is a good practice to free unneeded memory through code. This
helps the garbage collector figure out what memory can be freed. Memory used by timeline or
global objects can be freed by using the delete statement. Memory used by local objects can be freed by setting the referring variable
to null. Setting a variable
to null actually just reduces
the reference count of the object. The memory used by that object is freed when
the count is zero. In other words, when no other references to that object
exists.
Flash Lite frees the memory in two phases – mark phase and a sweep phase – based on a very well-known garbage collection method called mark-and-sweep. In the mark phase, the collector marks the objects that are not referenced by the application anymore and frees the memory in the sweep phase. Both the phases execute every time Flash Lite fires up the garbage collection process.