1 Reply Latest reply on Apr 15, 2010 3:27 PM by MarketlinxDev

    Flex Builder 3 - Memory Profile Confusion!

    MarketlinxDev Level 1

      Hello,

       

      I'm currently working on memory leaks in a fairly large application. When I finally tracked down the issue it had to do with using BindUtils's bindProperty method. If I assigned my properties directly and manually updated them, all of the instances were relased when the garbage collector was invoked (all of this through the memory profiler in Flex Builder Pro 3).

       

      I then build out a small little test app that simply created an ArrayCollection then using BindingUtils, bound it to the dataProvider of 20 data grids. I stored the change watches then manually called "unwatch" and finally nulled out the changeWatchers (and even went so far to manually remove the grids and null them out).

       

      What I noticed was when I used bindingutils, the ListCollectionView objects were not released when I used BindingUtils but when I used direct assignment and removed the grids, all the ListCollectionView instances were dumped correctly.

       

      At this point I'm not sure if I'm misinterpeting the results in the memory profiler or not. If I "unwatch" a change watcher and destroy it, should that kill and references to the target object? Any help or advice would be appreciated.

       

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="
      http://www.adobe.com/2006/mxml"
                      layout="absolute"
                      initialize="initData()">
          <mx:Script>
              <![CDATA[
                  import mx.binding.utils.ChangeWatcher;
                  import mx.controls.DataGrid;
                  import mx.binding.utils.BindingUtils;
                  import mx.controls.Label;
                  import mx.collections.ArrayCollection;

                  [Bindable]
                  public var dataProvider:ArrayCollection;

                  private var changeWatchers:Array;

                  private function initData():void
                  {
                      var object1:Object = new Object();
                      object1["first"] = "John";
                      object1["middle"] = "Alexander";
                      object1["last"] = "Smith";
                      dataProvider = new ArrayCollection();
                      dataProvider.addItem(object1);
                  }

                  private function createObjects():void
                  {
                      changeWatchers = new Array();

                      for (var i:int = 0; i < 20; i++)
                      {
                          var newGrid:DataGrid = new DataGrid();
                          changeWatchers.push(BindingUtils.bindProperty(newGrid, "dataProvider", this, "dataProvider"));
                          //newGrid.dataProvider = dataProvider;
                          targetItems.addChild(newGrid);
                      }
                  }

                  private function deleteMemory():void
                  {
                      for each (var cw:ChangeWatcher in changeWatchers)
                      {
                          cw.unwatch();
                          cw = null;
                      }

                      var children:Array = targetItems.getChildren();
                      for each (var child:DisplayObject in children)
                      {
                          targetItems.removeChild(child);
                          child = null;
                      }
                  }
              ]]>
          </mx:Script>

          <mx:HBox y="0">
              <mx:Button label="Create Grids"
                         click="createObjects()"/>
              <mx:Button label="Delete Grids"
                         click="deleteMemory()"/>
          </mx:HBox>
          <mx:VBox id="targetItems"
                   y="50">

          </mx:VBox>
      </mx:Application>

       

      Memory.JPG

        • 1. Re: Flex Builder 3 - Memory Profile Confusion!
          MarketlinxDev Level 1

          I answered my own question.

           

          In the code I was calling "unwatch" and setting the array element to null and I assumed that would cause the instances of ListCollectionView to decrease once the garbage collector was invoked. It wasn't till now that I was playing around with the code and set the array itself to null that it decreased the instances back to 0.

           

          At least I know where some of my memory issues could be coming from in the main application as I use arrays quite a bit!