Suppose I have a static method like this:
public static void doSomething() {
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
something();
}
};
timer.schedule(task, 1000);
}
When the function returns there is no more reference to the timer or the task. Is it possible that they will be garbage collected before the task is allowed to run? If not, why?