I have a question about the Spark DataGrid and how it works in terms of garbage collection. What I'm finding is that if I dynamically add and remove columns from the DataGrid at runtime, the GridColumns and ItemRenderers never get freed from memory.
For instance, if I have a list with 10 items and I create 10 columns, there will be 100 ItemRenderers and 10 GridColumns. If I remove all of the columns, they are still there.
If I add 5 columns back, it does not appear to instantiate more GridColumns or ItemRenderers - there are still 100 total renderers and 10 columns in memory.
This doesn't happen with the MX DataGrid. As the columns are removed the ItemRenderers and and DataGridColumns get freed from memory, when I look at the profiler afterwards, I see 0 ItemRenderers and 1 DataGridColumn.
Does anybody have any idea about what would be going on here? Or am I just missing something?
Here is the code that I used to test the Spark DataGrid:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<s:ArrayList id="dp">
<fx:Object label="label 1"/>
<fx:Object label="label 2"/>
<fx:Object label="label 3"/>
<fx:Object label="label 4"/>
<fx:Object label="label 5"/>
<fx:Object label="label 6"/>
<fx:Object label="label 7"/>
<fx:Object label="label 8"/>
<fx:Object label="label 9"/>
<fx:Object label="label 10"/>
</s:ArrayList>
<s:ArrayList id="columns">
<s:GridColumn dataField="label"/>
</s:ArrayList>
</fx:Declarations>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:DataGrid dataProvider="{dp}" columns="{columns}" width="100%" height="100%"/>
<s:HGroup>
<s:Button label="Add Column" click="columns.addItem(new GridColumn('label'))"/>
<s:Button label="Remove Column" click="if( columns.length > 0 ) columns.removeItemAt(0)"/>
</s:HGroup>
</s:Application>