The above scenario is not recommended.
setinterval)In this case the GC works in between steps "b" and "d" and the memory is reused.
Delete variables or set them to null when you no longer need them. Doing this marks the data for garbage collection. Deleting variables helps optimize memory use during runtime, because unneeded assets are removed from the SWF file.
The following two code examples show how to free memory that objects use by deleting the variable that references those objects. The examples are identical, except the first example creates a timeline and global variable and the second creates a local variable.
// Global and Timeline Variables: // variable attached to a movie or movie clip timeline var mcDateObject = new Date(); // Creates the Date object. trace(mcDateObject); // Returns the current date as a string. delete mcDateObject; // Deletes the object. trace(mcDateObject); // Returns undefined. // global variable attached to a movie or movie clip timeline _global.gDateObject = new Date(); // Creates the Date object. trace(_global.gDateObject); // Returns the current date. delete _global.gDateObject; // Deletes the object. trace(_global.gDateObject); // Returns undefined.
As mentioned previously, you can't use the delete statement to free memory that a
local function variable uses. Instead, you can set the variable reference to null, which has the same effect as using delete. The following code
example demonstrates this.
// Local Variables:
function func()
{
var funcDateObject = new Date(); // Creates Date object.
trace(funcDateObject); // Returns current date(string).
delete funcDateObject; // No effect.
trace(funcDateObject); // Still returns current date.
funcDateObject = null; // Sets object reference to null
trace(funcDateObject); // Returns null.
}
func(); // Calls func() function.
removeListener( ) before garbage collection.LoadMovie / Unloadmovie to inform the GC about freeing memory.The tips and procedures I've included in this article should help you better manage the memory requirements of your Flash Lite content.
Follow these links for more tips on creating content for mobile devices:
Flash Lite bitmap and vector graphics in mobile devices
Optimizing ActionScript for Flash Lite content on mobile devices