我注意到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条答案
按热度按时间vawmfj5a1#
这不是内存泄漏,而是活动项的循环。
onCreationComplete
是在完成渲染并在场景中显示datagrid时调用的,则必须在单击栅格时添加该项(selectedItem
事件)。