Reputation: 2288
We have Spark dataGrid which Contains many ItemRenderers. we load more than 200 rows every time. This causes memory leak in our app. So Is there any way to free the ItemRenderers?
Problem is almost similar to THIS while profiling
the instances keep going up and up, I'm using an arrayCollection as the dataprovider. I even call the dataprovider (arrayCollection) .removeAll() and the display goes blank, yet the number of instances of the itemRenderer does not go down. I then run the garbage collector in the profiler, and the item renderers still stay in memory. How can I remove the itemRenderers from memory?
Upvotes: 0
Views: 673
Reputation: 1713
make sure your item renderers do not use event handlers in the mxml, as mxml event handlers do not use weak references and thus never get GCed.
For example: I had an itemrenderer component in mxml that looked like <s:ItemRenderer creationComplete="OnCreationComplete">
instead I created a base class: public class ItemRendererBase extends ItemRenderer and in the constructor added the event listener this.addEventListener(FlexEvent.CreationComplete, OnCreationComplete, false, 0, true)
for sub component event handlers such as <s:Button click="OnClickButton"/> remove the inline event wiring and instead wire the event handler in your override OnCreationComplete with false, 0, true to use a weak reference.
also make sure you manually invoke the GC collection for testing this and I recomend using adobe scout
Upvotes: 0