I'm doing some exercices from a java certification book. In a question about the Garbage collection, they present the following code:
class Test {
private Demo d;
void start() {
d = new Demo();
this.takeDemo(d);
}
void takeDemo(Demo demo) {
demo = null;
demo = new Demo();
}
}
And the question is
When is the Demo object, created on line 4, eligible for garbage collection?
I'd say it can be collected after the instruction demo=null; because there are no longer references to it, but in the answer they give is:
When the instance running this code is made eligible for garbage collection
What am I missing?