1 Reply Latest reply on Jul 14, 2009 4:43 PM by rfrishbe

    Remove IVisualElement

    Bitoiu

      Hi,

       

      I'm developing an enterprise app, that I'm migrating from AS2 to Flex 4.

       

      There are a few core modules that I load directly on the application container.

       

      In flex 3 I added a child to the Application.application and then could remove it before adding another one.

       

      In Flex 4 I'm using addElement on FlexGlobals.topLevelApplication but then I cannot remove it.

      This is for the center area, where several modules can be placed, one each time.

       

      So before i load another module I want to unload the previous.

       

      I used Chrome to see the Flash Player memory in Flex 3 and with addChild/DisplayObject if I removed and added the same module over and over again the momory increase was insignificant.

       

      In Flex 4 if I do the following code over and over I keep incrementing the player memory, and I dind't find a way to remove the screenVElement before adding another on top.

       

      screenVElement = FlexGlobals.topLevelApplication.addElement(screenModule.factory.create() as IVisualElement);

       

      Some considerations:

       

      - I might add a spark Group if you think its a bad practice to add elements on the spark app;

      - I'm using add element because I couldn't do Add Child as a Display Object of the module ( that's how I did it in Flex 3);

      - I know AddElement is not a method of FlexGlobals.topLevelApplication but it worked. However I like to do things the correct way.

       

      Any help would be usefull. Thanks.

       

      Vitor.

       

      PS: This also didn't work, memory still increases dispite the element being removed and then added like supposed to.

       

      // Remove element if it was created before

      if ( screenVElement != null ) FlexGlobals.topLevelApplication.removeElement(screenVElement);

       

       

       

      // Add an instance of the module's class to the          

      screenVElement = FlexGlobals.topLevelApplication.addElement(screenModule.factory.create() as IVisualElement);

        • 1. Re: Remove IVisualElement
          rfrishbe Level 3

          Hey Vitor,

           

          Your use of addElement seems correct here.  As per this memory issue, I think I'd need to look at a test case.  Perhaps there is a memory leak in Group or SkinnableContainer keeping a reference to the module somehow.  Or perhaps it's just getting delayed with the GC more than in the Halo case because there are extra temporary references.  At any rate, it's just speculation.  A test case would help, but the way to debug it yourself would be to take a look using the profiler.

           

          -Ryan