0 Replies Latest reply on Sep 12, 2012 7:22 AM by jozefchutka

    DataGrid.selectedIndex memory leak

    jozefchutka Level 1

      Hello again,

      I have noticed a memory leak in a DataGrid, in case I do not select an item, I am able to GC my dataGrid, if there was anything selected then dataGrid cause memory leak...

      here is the simpliest example:

       

      <?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>
      
      

       

      if you comment out line "container.selectedIndex = 0;" DataGrid gets GCed nicely.

      Any ideas how to GC DataGrid with selected item?

      I am using flex 4.6.0