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.
itemRenderer2 : 47
itemRenderer1 : 59
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.