[flexcoders] Wicked Memory Leaks and Massive Loitering Objects

2009-02-20 Thread Adrian Williams

Hi all,

   My forehead is becoming flatter by the minute as I bang my head 
against the wall on this one


   In my dashboard application, I have a tab navigator with a canvas 
that defines each tab.  A single tab/canvas has numerous panels and each 
panel has a swfloader swf file.  When a user clicks on a different tab, 
I'm trying to unload all the components on the tab (canvas.removeAll()) 
before making the switch...in an effort to free up the memoryI've 
made sure to go thru and add appropriate listener removals but when I 
run the app, I end up like an ant standing in front of Hoover dam, 
yelling Bring it on!!.  After clicking the third tab, memory is maxed 
and FF crashes


   So, I've run this sucker through the flex profilertaken 
snapshots and compared to find loitering objects...holy crapthere 
are PAGES of loitering objects...with the top two offenders being 62,000 
String instances taking up 3,233,462 (30.01%) of memory and 439 Class 
instances taking up 3,308,623 (30.71%) of memory.  Upon investigation, 
every freakin string that is returned from my web service calls and used 
in the panels is saved in memory...


   The rest of the top ten list are:  UITextField, Function, Object, 
Array, Button, QName, WSDLMessagePart and UIComponent. (wtf is QName???)


   I've poured thru what I can find on the net about getting rid of all 
this junk...and haven't found much. I'm seriously hoping for some help 
because we cannot go public beta with this until I get the memory 
problems ironed out. 


   I found some information that is perplexing...

   1.)  The removeAll() doesn't actually unload anything from memory??  
It only removes it from the container??  What!?!


   2.)  I scrapped the removeAll() and tried instead to use the 
delete() function, cycling thru all the panels on the canvas and doing a 
delete panel.  That pukes on me with the error 1189: Attempt to delete 
the fixed property mdiwindow.  Only dynamically defined properties can 
be deleted. 


   3.)  It seems that renderer's like to hang out for a while and enjoy 
the show...with no clear way to get rid of them (kinda like my Uncle Jesse)


   So, folks, all help here would certainly be appreciatedhow in 
the world do I get this stuff cleared out?  Should I be trying to unload 
the swf's or will that results in the same thing as the 
removeAll()...gone...but not really?


Looking forward to getting this resolved,
Adrian



RE: [flexcoders] Wicked Memory Leaks and Massive Loitering Objects

2009-02-20 Thread Yves Riel
I like your humour Adrian!
 
The loitering objects can be caused by many things. During my track down
on leaks, I found out that most of the time, it was forgetting to set a
property to null, not removing listeners as I expected, etc. Without
seeing code, it's difficult to help you out properly. However, here are
some things to ponder:

*   
Allow for null values on all properties. When the null values
are received, do a clean up and release all references. This is
especially useful when you have bindings going on.
*   
If you can't easily remove a listener, make it week by setting
the last parameters of AddEventListeners() to true.
*   
If you are using a Dictionary, allow for weak references: new
Dictionary(true).
*   
Item renderers do not release their reference to the data. You
can built a helper function that can do this for you. (See attached
file)
*   
Alex Harui made a nice tutorial if you're not too familiar with
the profiler (
http://blogs.adobe.com/aharui/2008/09/using_the_flex_builder_3x_prof.htm
l)

And be patient, at the end, you'll be able (unless there's a bug) to
remove all bad references using the profiler.
 
Yves
 


CleanUp.as
Description: CleanUp.as