Using Spark Datagrid Memory with Dynamic Columns

I have a question about Spark DataGrid and how it works in terms of garbage collection. I find that if I dynamically add and remove columns from a DataGrid at runtime, GridColumns and ItemRenderers are never freed from memory.

For example, if I have a list of 10 items and I create 10 columns, there will be 100 ItemRenderers and 10 GridColumns. If I delete all columns, they still exist.

If I add 5 columns back, it will not create instances of more GridColumns or ItemRenderers - there are 100 more regenerators and 10 columns in the memory.

This does not happen with MX DataGrid. When the columns are deleted, ItemRenderers and DataGridColumns are freed from memory, when I look at the profiler afterwards, I see 0 ItemRenderers and 1 DataGridColumn.

Does anyone know what will be here? Or am I just missing something?

Here is the code 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>
+3
source share
2 answers

I have not yet had the opportunity to view the DataGrid Flex 4.5 code, but I would suggest that they use object aggregation to render items.

DataGrid - , , , - ( ). DataGrid, "" . ; , . , DataGrid.

, Google :

DataGrid IFactory IVisualElements. GraphicElements, Rect , , Flex DisplayObject . , , , , DataGrid.

, DataGrid, DataGrids. , . , , Flex DataGrids.

+1

, - useVirtualLayout.

. , > . , , , , , .

, useVirtualLayout true , . DataGroup SkinnableDataContainer , VerticalLayout, HorizontalLayout TileLayout, . , , "

: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/layouts/supportClasses/LayoutBase.html#useVirtualLayout

. , DataGrids VirtualLayouts, "GridLayout". , , .

0

All Articles