Memory issues in Flex applications

Hi

As we all know that for any application runtime memory plays a crucial role. And every technology handles memory clean up in their own way, in fact the API’s offered by the technologies doesn’t guarantees the same.

Few days back I was struggling with my application which is having a UI interface based on Flex. And in one of the interface we started getting out of memory issues,  First of all lots of time goes waste in finding the root cause of the memory issues, Thanks to the debug version of the Flash player 10 who helped us to get the root cause.

There are plenty of things I will detailed to avoid out of memory issues in Flex based applications, I will publish those in my next blog. But as a quick workaround we can call the garbage collector to clean the memory in the Flash Player. Flex 3 System API is having a method called Syatem.gc() but sometime not found working. In flash there is no way to explicitly invoke the garbage collector, but on the web there is a hack(below) that can be found easily.

public static function forceGarbageCollecion():void{ // hack for garbage collection
trace(“Total Memory:”+flash.system.System.totalMemory);
try{
var loclConA:LocalConnection= new LocalConnection();
var loclConB:LocalConnection = new LocalConnection();
loclConA.connect(‘gcConnection’);
loclConB.connect(‘gcConnection’);
}catch (e:Error){
trace(“Error ::”+e);
flash.system.System.gc(); // incase some error occurred, invoke the System Garbage collector
}
trace(“Total Memory:”+flash.system.System.totalMemory);

}

Hope this helps!!

Thanks

R Vashi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s