2 Replies Latest reply on Oct 4, 2007 1:12 PM by StudioCloud

    garbage collection

    StudioCloud Level 1
      I'm having problems getting a panel in a viewstack to get garbage collected. I'm using the new flex builder profiler and the attached code below.

      Here are the steps I take:

      1. launch the testApp with the profiler.
      2. click the add panel button and watch until the remotePanel shows up in the live objects pane of the profiler.
      3. click the remove panel button and watch as the panel is removed, the object is set to null, but the remotePanel object never leaves the live object pane which implies that it is not being garbage collected.

      Does anybody know what I'm doing wrong?

      //Main App
      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      <![CDATA[
      import mx.containers.Panel;

      public function addPanel():void
      {
      var tmpPanel:remotePanel = new remotePanel();
      panelViewStack.addChildAt(tmpPanel,0);
      }

      public function removePanel():void
      {
      if (panelViewStack.getChildren().length >0)
      {
      var tmpPanel:Panel = panelViewStack.getChildAt(0) as Panel;
      tmpPanel = null;
      panelViewStack.removeChildAt(0);
      }
      }

      ]]>
      </mx:Script>

      <mx:VBox>
      <mx:HBox>
      <mx:Button label="Add Panel" click="addPanel()"/>
      <mx:Button label="Remove Panel" click="removePanel()"/>
      </mx:HBox>
      <mx:ViewStack id="panelViewStack" width="100%" height="100%"/>
      </mx:VBox>
      </mx:WindowedApplication>

      //Remote Panel
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Panel xmlns:mx=" http://www.adobe.com/2006/mxml" title="Remote Panel">
      </mx:Panel>
        • 1. Re: garbage collection
          StudioCloud Level 1
          The previous code was for an adobe air app. Below is the flex code. It has the same issue.


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
          <![CDATA[
          public function addView():void {
          var tmpPanel:remotePanel = new remotePanel();
          panelViewStack.addChildAt(tmpPanel,0);
          }

          public function removeView():void{
          if (panelViewStack.getChildren().length >0)
          {
          var tmpPanel:remotePanel = panelViewStack.getChildAt(0) as remotePanel;
          tmpPanel = null;
          panelViewStack.removeChildAt(0);
          }
          }

          ]]>
          </mx:Script>

          <mx:VBox x="0" y="0" height="100%" width="100%">
          <mx:ApplicationControlBar width="100%" horizontalAlign="center">
          <mx:Button label="Add Panel" click="addView()"/>
          <mx:Button label="Remove Panel" click="removeView()"/>
          </mx:ApplicationControlBar>
          <mx:ViewStack id="panelViewStack" width="100%" height="100%">
          </mx:ViewStack>
          </mx:VBox>
          </mx:Application>


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Panel xmlns:mx=" http://www.adobe.com/2006/mxml"
          width="100%" height="100%" title="Remote Panel">
          </mx:Panel>
          • 2. Re: garbage collection
            StudioCloud Level 1
            looks like this is a memory leak in adobe air. Flex correctly does garbage collection on the example code while adobe air does not.