Question

What happens to class that extends TimerTask after it's run method has been executed? Is value for myTask null or what after execution?

MyTask myTask = new MyTask();
Was it helpful?

Solution

If you started it from a method that has since ended (and didn't reference it anywhere, e.g. in a member variable of an object that's still alive) it will be cleaned up by the garbage collector.

There's no need to set it to null unless the Task keeps references to huge amounts of memory.

If you really need to de-reference the Task you should add a call at the end of its run() method to discard it from wherever you are referencing it from.

OTHER TIPS

Nothing. You can check the source code of the Timer class, to understand what is really happening under the hood when a TimerTask is scheduled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top