Useful Flash Lite Development Tool

For those of you that are developing Flash Lite applications and games you will be well aware of the issues of Memory leaks in the Flash lite player. One area where this can occur is in the creation of “crossed references”. These result in objects that are effectively locked as far as Garbage Collection is concerned, and so result in memory ‘leaking’ over time.

A crossed reference occurs in situations such as this.

[as]
var myFirstObject:Object = new Object();
var mySecondObject:Object = new Object();

myFirstObject.reference = mySecondObject;
mySecondObject.reference = myFirstObject;

myFirstObject = null;
mySecondObject = null;

delete myFirstObject;
delete mySecondObject;
[/as]

In each case the objects above have a property that references an object, and the reference is cyclical in nature. As far as the Garbage Collection routine in the player is concerned each object will always have a usage count of 1 regardless of the delete statements as a result of the reference in the other object. The result is that neither object will be cleared from memory, hence the leak. If such a situation were to arise in a looping operation the loss of memory is compounded.

[as]
var i:Number = 0;
var iTotal:Number = 5;

whie(i < iTotal) { var myFirstObject:Object = new Object(); var mySecondObject:Object = new Object(); myFirstObject.reference = mySecondObject; mySecondObject.reference = myFirstObject; myFirstObject = null; mySecondObject = null; delete myFirstObject; delete mySecondObject; ++i; } [/as] Now the above example is a very simplistic example, and is very plain to avoid. With more complex applications however, these situations can arise over many classes and may not be any where near as blatant. This little flash extension offers a great interface for highlighting those crossed references in small applications vital for Flash Lite developers to find and remove. object-explorer

Leave a Reply

Your email address will not be published. Required fields are marked *