Using the Flex Builder 3.x Profiler
I've been getting lots of questions about memory leaks lately. I finally found some time to put my techniques for analyzing memory leaks into writing.
Instead of using PowerPoint, I actually created a SWF so you can use the SWF to both view the presentation and learn how to use the Profiler. I cover the differences between profiler memory, System.totalMemory and process memory and show how I analyze the two most common memory leak scenarios.
As usual, caveats apply.
The SWF also demonstrates an approach to another topic I've heard about often, and that is how to do XML-driven or data-driven UI. The presentation in this SWF is controlled by an XML file. A single engine parses the XML and creates the UI widgets as dictated by the XML. To change the presentation, all I have to do is change the XML. I can also add new widgets easily. Source is available here:
The SWF also demonstrates a technique for improving startup time. Because our blog system is painful to use, I don't like uploading more than one or two files per blog post, but this presentation had more than a dozen images. So, instead of loading images externally, I embedded them into the SWF, but normally, that delays startup by the download time of all of those images. To get around that, I pack all the images into frame 3 of the SWF so that Flex can get up and running while the images download at the end of the SWF. I can get away with that because the images are not needed right away.
Hope this helps.
Comments
An excellent resource about memory profile, thanks Alex!!
Posted by: ivan alvarez frias | September 6, 2008 9:11 AM
You rock Alex! :) Thanks for providing such good info all the time!
Posted by: Jun Heider | September 24, 2008 10:23 AM
I always wanted to learn more about the profiler, thank you Alex !
Maybe a little off topic but I would like to know where to get profiler version of FP 9.0.124 (it exists?) ? I actually have Socket Timeout issue with normal 9.0.124.
------------------------
Alex responds:
The debugger player for any FP should support the Profiler. I'm using .124 w/o problems
Posted by: Adnan Doric | October 3, 2008 2:35 AM
I'm working on a flex app that is using BlazeDS to call some EJBs on the backend. As such I really need my swf to run in the context of an application server so the EJB stuff works correctly.
Do you know if the profiler supports this? All I can figure out how to make it do is profile my swf in a standalone mode, which doesn't really let me do anything useful.
Your tutorial is great though, I like that it lets me click through at my own speed, all the other tutorials I found are text only w/ no pictures, or are long movies with very poor seeking control.
---------------------------
Alex responds:
"in context" as in the ability to profile the EJB's response to a request from the SWF and vice-versa? I'm not sure what data you are looking for?
Posted by: Jim Johnson | October 3, 2008 3:27 PM
Hello Alex!
I am afraid you are the only one on the earth who explained the difference between the memory shown in system.totalmemory and the numbers shown in windows task manager! Thanks so much!!
I have two questions not sure if you have any idea.
1) system.totalMemory shows very small values in IE7 as compared to firefox, is this a known bug?
2) Consistently, some of my swf can have 1.7GB shown in the system.totalMemory but only 58MB shown in the windows task manager. This is terrible, what might be the cause for this?
----------------------
Alex responds:
IE7 will show different numbers than FF, but it shouldn't vary that widely. If you have a simple way to reproduce the problem, feel free to file a bug.
One of my colleagues is no longer trusting Task Manager and so we're now using ProcessMonitor and private bytes. See what you get for numbers with ProcMon
Posted by: Terrence | November 7, 2008 2:46 AM
Thanks for the great presentation!
i am still looking for some further details about garbage collection and the flashplayer internal actions ([keyboardEvent], [pre-render]) shown up in the profiler. are there any further online resources about these topics?
i know already these resources:
http://livedocs.adobe.com/flex/3/html/help.html?content=profiler_3.html
https://developer.mozilla.org/en/MMgc
one question to gc:
the gc uses besides mark and sweep the drc (deferred reference counter). so when i nullify an object which i dont need anymore, the reference counter should be updated and if it gets the value 0 the object is free for gc. so would it help for performance to nullify all unused objects (of course thats a boring piece of work)? i guess the mark and sweep will have less work as it should ignore objects already updated by reference counter to value 0.
-----------------
Alex responds:
I don't know of any official documentation on the names wrapped in [] in a profiler report. Note that the player is not written AS so these [] names are more like "phases" or "states" that it is in.
I also don't know which objects are guaranteed to be DRC objects so I don't normally write code that makes such assumptions and starts nulling things to try to get the refcount to zero sooner. So far, just treating everything like objects in a mark/sweep gc has worked for me.
Posted by: Manfred Karrer | April 26, 2009 4:14 AM