posted 22 years ago
The strict answer to the question is that the garbage collector could be invoked at any time by the JVM.
I think that the question should be: What is the first line after which an object created in main is eligible for garbage collection? (I'm also assuming that object is a valid class defined elsewhere.)
The answer I would give is "After line 6", because after line 6, the object created in line 5 is no longer referenced.
However, the object created in line 4 will only be eligible for garbage collection after line 8, when both variables no longer refer to it.
[ February 24, 2003: Message edited by: John Paverd ]