Reputation: 2212
If I make a timer such as
var timer:Timer = new Timer(50, 0);
timer.addEventListener(TimerEvent.TIMER, OnTimer);
timer.start();
and then my function ends, you would think this timer has gone out of scope and nothing is holding on to a reference of it anymore. However this timer still works.
So either I am getting lucky and the garbage collector hasn't run yet or something is holding on to a reference. If it is the latter then how will I know it is going to be garbage collected?
Upvotes: 1
Views: 55
Reputation: 7784
Timer will still run and will be dispatching events. Just declare it the way you can access it (as public instance variable) and perform:
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, OnTimer);
- VERY important thing in Flashtimer = null;
- if you really need to free memory, set the reference to nullUpvotes: 2