Originally posted by suresh mulagala:
Unless the old object is static i guess ....?
Objects are never static, references are static.
As you said before, if in method m2, some code like this is present:
q3[index++] = q1,
where q3 is either an instance variable(of an instance that is not eligible for gc) or a static variable(if the classloader is not eligible for gc).
index is again a static integer.
In this case, none of the objects will be eligible for gc.
However, if the code is as follows:
q3 = q1
Then 9 objects will be eligible for garbage collection as the above code will only hold on the last object created.
Hope it is clear.