4 Replies Latest reply on Aug 11, 2010 10:06 PM by flex4

    Deleting / garbage collecting old instances?

    mike_morales Level 2

      Hey all,


      I've got a question about deleting/garbage collecting old instances. Here is where I have encountered this, within my app I call a method that dynamically instantiates a custom class, and adds it to a container (an HGroup for example).  The custom class accepts data, then dispatches an event to which my app is listening for.


      Now, I would like to delete the custom class that was instantiated from my app. I don't think I have a reference to it other than myHGroup.getElementAt(myHGroup.numElements-1) since it was dynamically created within a function (I don't want to instantiate it till it is needed because it will not always be needed). So as of now, my procedure for deleting the instance is to create a temporary instance myTempClass:MyClass=myHGroup.getElementAt(myHGroup.numElements-1) as MyClass, then setting it to null,  myTempClass=null; then removing it from the HGroup. Will this sufficiently delete the instance from memory? Is it as easy as setting the instance to null? Below is some example code of the above:


      private function createForm():void{

           var tempForm:MyForm = new MyForm();





      private function formHandler(event:Event):void{

          var myTempClass:MyForm=myHGroup.getElementAt(myHGroup.numElements-1) as MyForm;





      Will that do the trick? and under normal circumstances, if you set an instance to null, with that ready it for garbage collection?


      Thanks in advance, much appreciated!