Memory Leak – Changing ColumnSeries itemRenderer at runtime – FLEXDMV-1882
November 10, 2008
I wanted to post this small fix that I tried out for fixing the memory leak when changing itemRenderers for a flex chart.
The sample files for the bug mentioned in http://bugs.adobe.com/jira/browse/FLEXDMV-1882 are used to illustrate the fix.
The fix done was, to set the instance cache of the itemRenderer in ColumnSeries to be removed when not being used. Specifically the following needs to be done.
1. Goto this function in ColumnSeries.as which is part of your DMV source at src\mx\charts\series\ColumnSeries.as
override public function styleChanged(styleProp : String) : void
2. For the condition – else if(styleProp == “itemRenderer”)
Have the following code
_instanceCache.discard = true;
_instanceCache.remove = true;
_instanceCache.count = 0;
_instanceCache.remove = false;
_instanceCache.discard = false;
This should take care of removing unwanted instances when the itemRenderer gets changed.
I ran the sample without and with the changes for 1 minute by changing the itemRenderer every 5 seconds. Here is the result of that, i.e. the itemRenderers that needed to get updated at that given time. Notice the number of itemRenderers that existed after the change is far fewer than the one without the change.
With Change
itemRenderer2 : 47
itemRenderer1 : 59
Without Change
itemRenderer2 : 391
itemRenderer1 : 451
This fix is only for ColumnSeries, if you want it for any other series make sure to make similar changes in that file as well.
Let me know if this fixes the memory leak on changing of item renderers as well as some of the real-time flex charting itemRenderer related memory leaks.

November 11, 2008 at 5:11 pm
Thanks Sunil.
I’m not sure, though, how I can access _instanceCache, since it’s declared as private.
-Eddie
November 12, 2008 at 4:20 am
Hi Eddie, You cannot change this by overriding the function, you have to modify the source in ColumnSeries.as
April 29, 2010 at 11:31 pm
Hey sunban, I thought i was the only person in the world with this problem. I am having a similar issue like this for the linechart. I’m using multi axes, so when i remove a verticalaxis that is not being used, the chart responds appropriately, but the old axisrenderer is still visible in the background. How can I remove that axisrenderer from the chart’s memory. Thanks so much.
tonihb
April 30, 2010 at 7:02 am
1. Remove it from the corresponding axisRenderers array
2. Call chart.removeChild(axisRenderer)
April 30, 2010 at 2:01 pm
That did the trick!! Thank you so much!
tonihb