DataGrid.selectedIndex内存泄漏

时间:2012-09-12 14:35:12

标签: actionscript-3 flex memory datagrid memory-leaks

我注意到DataGrid中存在内存泄漏,如果我没有选择项目,我能够GC我的dataGrid,如果有任何选择,那么dataGrid导致内存泄漏... 这是最简单的例子:

<?xml version="1.0" encoding="utf-8"?>
<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:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.collections.ArrayList;

            import spark.components.gridClasses.GridColumn;

            [Bindable]
            private var columns:ArrayList = new ArrayList;

            [Bindable]
            private var dataProvider:ArrayCollection = new ArrayCollection;

            private function onCreationComplete():void
            {
                dataProvider.addItem({id:1});

                var column:GridColumn = new GridColumn;
                column.dataField = id;
                columns.addItem(column);

                container.selectedIndex = 0;
            }

            private function gotoOne():void
            {
                currentState = one;
            }

            private function gotoTwo():void
            {
                columns = null;

                currentState = two;
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="one"/>
        <s:State name="two"/>
    </s:states>

    <s:Button click="gotoOne()" label="one"/>
    <s:Button click="gotoTwo()" label="two" left="150"/>

    <s:DataGrid id="container" top="30" includeIn="one" itemDestructionPolicy="auto"
                creationComplete="onCreationComplete()" columns="{columns}"
                dataProvider="{dataProvider}"/>
</s:Application>

如果你注释掉行“container.selectedIndex = 0;” DataGrid很好地获得了GC。 任何有关所选项目的GC DataGrid的想法? 我使用的是flex 4.6.0

1 个答案:

答案 0 :(得分:0)

这不是内存泄漏,而是实时项目的循环。

在场景中完成渲染并显示datagrid时会调用

onCreationComplete,您必须在点击网格(selectedItem事件)时添加该项目。