All r1, r2, r3 objects are in an island of links. So if r2 is alive then anything linked to it cannot be gc-ed, which mean r3 cannot be gc-ed, but since r3 has a link to r1, that makes r1 not gc-able. So for an island of links, only if all of them are null-out, you cannot gc any of them because they are all linked in a closed chain to each other.
Joined: May 09, 2006
So for an island of links, only if all of them are null-out, you cannot gc any of them because they are all linked in a closed chain to each other.
Right after line 14, we have r1=r2=r3=null;
So we have an island of isolation (eligible for GC) RIGHT after line 14.
But in line 15, one of them could be made to point to an object. So why isn't the answer "Could not be determined"?
After all, GC depends on what line 15 does, right?
The question asks when will the first object be eligible for garbage collection. And, after line 14 all the three objects loose their references. And, these objects cannot be referenced again. Whatever, you try to do with the references after line 14 you cannot recover the objects eligible for collection, unless and until you use the finalize(), which is not the case here.
SCJP 1.4 85%
subject: After which line obj become eligible fo GC?