views:

95

answers:

3

How do you know if your compiled SWF file has a memory leak?

Are there tools, a firebug setting, etc... to see if there is a problem? I cannot find much in the debug Flash player besides file size and loading time.

I have a large Flash application that I maintain and suspect that is using way too much memory so I wanted to measure the amount of RAM being used while it executes to find key areas to optimize.

Any help would be greatly appreciated.

+3  A: 

All you can really do is examine your memory usage when the application starts, and as it is changed.

To get the amount of memory currently in use you can do:

var initial_memory:Number = Number(System.totalMemory/1024).toFixed(2));

do this at the very start of your application (ie, when everything has finished loading)

then, start a Timer and use TimerEvent.TIMER handler or add an Event.ENTER_FRAME event listener and do this:

var current_memory:Number = Number(System.totalMemory/1024).toFixed(2));

Now you have the initial_memory usage as well as the current_memory usage. How you choose to use these is up to you. You can subtract initial_memory from current_memory to get your delta. You can display them in a text field on your stage, write them to FireBug's console, or trace them in the output window.

Then just click around. If you do something that increases the memory, that is ok. But, if you have something that should be unloaded, and is not, then you have a leak.

sberry2A
Thank You. This is what I was needing.
Todd Moses
+1  A: 

Jun Hinder presented the basics for the Profiler at 360|Flex presentation in '09... or maybe that was '08... either way, I'd suggest looking into Profiler basics.

jeremym
+3  A: 

I would recommend you look at the Flex Builder profiler as well. If you compartmentalize code into a Module, load it, interact with it, then unload it, you can easily see if there are still classes from your module in memory. Usually this is due to event listeners that are not using weak references (the 5th parameter in the addEventListener method).

Also, this blog post and associated presentation on Flash Player memory management is worth a read:

http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html

cliff.meyers