Setting the timer to null it wont remove their listeners, before that
you need to remove it.
 
lifeTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onLifeTimer);
lifeTimer = null;
 
And you must remove every single listener to successfull get GC'ed

________________________________

De: [email protected] [mailto:[EMAIL PROTECTED] Em
nome de Paul Andrews
Enviada em: sexta-feira, 28 de novembro de 2008 09:26
Para: [email protected]
Assunto: Re: [flexcoders] How to get an object to delete itself?


Tom,
 
Setting alpha=0 won't make the object available for garbage collection.
If you don't want the oject any more you need to remove all references
to it. This will require that you remove it from the Display list and
remove any other references to it. You also need to remove the timer.
 
So your destruct method needs (at least):
 
this.owner.removeChild(this);   // remove this instance from the parent
container in the display list
lifeTimer = null;  //remove the reference to it
 
Paul
 

        ----- Original Message ----- 
        From: tom s <mailto:[EMAIL PROTECTED]>  
        To: [email protected] 
        Sent: Friday, November 28, 2008 11:08 AM
        Subject: [flexcoders] How to get an object to delete itself?

        I have custom class that extends UIComponent which I use for
putting graphics on to the stage (I add them as children of a seperate
UIComponent).
        In the constructor I create a Timer and watch for the
TIMER_COMPLETE event, at which point I want the graphic to dissapear,
which I do by setting alpha = 0. 
        However, I am concerned that it will not be garbage collected,
and I could end up with quite a few of these, which may be bad for
memory. 
         
        Question: Can i get the object to delete itself? (or atleast be
in a state suitable for grabage collection)
         
        e.g. this.selfDestruct() ;)
         
        The relevant code is shown below.
         
        thanks
         
        tom
         
         
        public

        class DrawingTool extends UIComponent 

        {

        

        

        private var lifeTimer:Timer = new Timer(8000,1); 

        

        

        

        public function DrawingTool():void{ 

        

        super(); 

        

        
lifeTimer.addEventListener(TimerEvent.TIMER_COMPLETE,onLifeTimer); 

        lifeTimer.start();

        }

        

        

        

         

        

        

        private function onLifeTimer(e:Event):void{ 

        

        this.alpha = 0 

        

        trace(">>>time out"); 

        

        }

        }

         

        

 

Reply via email to