Original Post
I have the following code in a class function :
public function foo():void
{
var timer:Timer = new Timer(10000,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);
timer.start();
}
public function onTimerComplete(e:TimerEvent):void
{
// do stuff
}
The above code works most of the time but my concern is what happens if timer gets garbage collected? Is it possible that onTimerComplete will never fire because there are no other references to timer?
For some discussion about this : http://stackoverflow.com/questions/5891354/actionscript-3-local-timer-object-event-handler
Basically I made a test app and created 500 timers and set all their delays to a high value like 60secs and then I spammed garbage collect in my profiler and none of the timers got garbage collected. But after the event handlers ran after 60secs hitting garbage collect freed all of those timers.
I have people saying that removeEventListener must be called on each timer or they wont get released. But this is not what I am observing.
I know timer has an internal list of handlers but that won't keep it from being GC'ed i think.