title: Spark Datagrid memory usage with dynamic columns
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Does anybody have any idea about what would be going on here? Or am I just
  missing something?</p>
  
  <p>Here is the code that I used to test the Spark DataGrid:</p>
  
  <pre><code>&lt;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"&gt;
      &lt;fx:Declarations&gt;
          &lt;s:ArrayList id="dp"&gt;
              &lt;fx:Object label="label 1"/&gt;
              &lt;fx:Object label="label 2"/&gt;
              &lt;fx:Object label="label 3"/&gt;
              &lt;fx:Object label="label 4"/&gt;
              &lt;fx:Object label="label 5"/&gt;
              &lt;fx:Object label="label 6"/&gt;
              &lt;fx:Object label="label 7"/&gt;
              &lt;fx:Object label="label 8"/&gt;
              &lt;fx:Object label="label 9"/&gt;
              &lt;fx:Object label="label 10"/&gt;
          &lt;/s:ArrayList&gt;
          &lt;s:ArrayList id="columns"&gt;
              &lt;s:GridColumn dataField="label"/&gt;
          &lt;/s:ArrayList&gt;
      &lt;/fx:Declarations&gt;
      &lt;s:layout&gt;
          &lt;s:VerticalLayout/&gt;
      &lt;/s:layout&gt;
      &lt;s:DataGrid dataProvider="{dp}" columns="{columns}" width="100%" height="100%"/&gt;
  
      &lt;s:HGroup&gt;
          &lt;s:Button label="Add Column" click="columns.addItem(new GridColumn('label'))"/&gt;
          &lt;s:Button label="Remove Column" click="if( columns.length &gt; 0 ) columns.removeItemAt(0)"/&gt;
      &lt;/s:HGroup&gt;
  &lt;/s:Application&gt;
  </code></pre>