Jerson Chua,
I want you to understand one point. It is taken for granted all the time.
1. String s1=new String("java");
2. s1 = null; 3. code 1
4. code 2
5. code 3
What does the 2nd line of statement do? It erases the s1 reference's value right?. Which mean erasing
is being done at line 2, and
erasing is OVER after execution if the statement at line 1. Do you agree with this? In the grayed area of GC mechanism in
Java, The bare minimum info
for sure , specified by JLS is this.
When an object looses all its refernces in the program, hangs in the heap without any reference point to it , it is ELIGIBLE for GC .
So setting a reference to null is in another way of saying I don't need this object anymore. We can also indicate that the object is not of interest any more by means of making the reference to refer to another object.
The more interesting point in these set of code is here , BOTH way of saying that the object is not of interest is done. But note that setting a ref to null itself ENOUGH. The referred object is ELIGIBLE FOR GC in there is no more ref pointing to it. Obviously the above set of code there is NO MORE PREVIOUS ref pointing to the object 'first'.
So the anser is correct. The 'first' object is ELIGIBLE for GC after line 6. That is before line 7.
regds
maha anna