At The Supergroup we do a large amount of Flash development. If you have ever developed in Flash you have most likely run up against the problem of memory leak. This typically happens when you are loading in lots of image files into your application. You might have experienced this on a Flash image gallery. After viewing images for a while, the application gets bogged down and performs really badly.
Ok. This is going to get pretty dev-talky so read ahead with caution…
The problem comes from adding and removing things to the display list in Flash. Flash depends on something called the “garbage collector” to come along and clear things out of memory that are no longer in use by your program. This frees up your computer. Here are step-by-step instructions for how to get your memory clear without having to do a page refresh.
Removing Objects and Marking Them for Garbage Collection
First thing is to remove the objects from the display list and set them to null.
Example:
for(var i:int = 0; i<images.length; i++){
images[i].unload();
removeChild(images[i]);
images[i] = null;
}
images = null;
You must remove anything that has a referential connection to the objects that you are removing or they will not be marked for garbage collection. As in our example, the images array holds a connection to each item in the array, so it must be removed as well in order to clear the objects from memory.
Here is a really good article about garbage collection.
Calling the Garbage Collector
Here at TSG, we did all that but there was no way of knowing if the garbage collector was actually coming around to pick up this trash. Instead of sitting there and seeing if the garbage collector would ever come around, we decided to try and call him up. We found two solutions:
1. The first is to open two local connections (it’s a total hack, but it works):
try {
new LocalConnection().connect(’foo’);
new LocalConnection().connect(’foo’);
} catch (e:*) {}
2. The second method is only available with the additional CS4 ActionScript libraries:
flash.system.System.gc();


A couple weeks ago, I got the
I’m a total podcast junkie; I typically always listen to them on my iPhone until I run out, then put music on. One I’ve been hooked on lately is 
