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 
  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