posted 23 years ago
I might be wrong, but I disagree with Tom. First off, Garbage Collection questions are usually asked "When is the OBJECT created at line X eligible for GC?" "o" is a reference to a string, not an object. The object is the String with the text "true".
An object is eligible for garbage collection when there are no active references to that object. In line 3, a second active reference is created when the first reference in the array oa is pointed at the string. Therefore, when o is set to null in line 4, there is still an active reference.
When oa[0] is set to "" in line 5, there are no longer any references to the string containing "true", so it is then eligible for GC, after line 5.
Matt