0 Replies Latest reply on Feb 10, 2008 1:17 AM by Ratsnackbar

    Dynamic Classes and Garbage Collection

    Ratsnackbar Level 2
      I asked this in the General Flex Forum and no one responded so I thought I would try again in this forum.
      ****************************************************************************************** *******************************

      I am injecting Classes into Containers using something similar to this code.

      private var myComponent:*;

      public function setCurrentEditor(_classPath:String):void{
      var myClass:Class = getDefinitionByName(_classPath) as Class;
      myComponent = new myClass();
      this.addChild(myComponent);
      }

      And I close out the container with something like this.

      public function closeThisWindow():void{
      this.myComponent.closeThis();
      this.myComponent = null;
      this.removeAllChildren();
      //remove this child from parent
      this.parent.removeChild(this);
      }

      The closeThis() method runs code in the child to have it release all listeners and null all vars.

      Unfortunately this method of loading classes has a few side effects I do not desire. Such as having to have Variable instances for each class so that they do not get scrubbed by the compiler. (Anyone know an easy solution to that I would be happy to hear it.)

      My actual question though is if you do this is the Garbage collector going to be able to collect this or am I setting myself up for Memory Leaks? (Assuming of course that the Class loaded does not already have leaks of it's own.)