The answer states (after removing the compile error): "'Never in this program' because until the last reference is nulled none of the objects is eligble, and once the last reference is nulled, all three are eligible."
I'm a bit confused of why afer e3 = null, e3 wouldn't be immediately eligble for garbage collection? Once e3 points to null, what still needs the reference to e3 that would make it not eligble?
The only thing I can see is that maybe since e1.e is still pointing to e3 that maybe that keeps it around? But that doesn't seem to make sense since if e3 is poining to null, I wouldn't think e1.e would still need the actual Echo e3 object around?
Thanks for some clarification.
Originally posted by Henry Wong:
Remember that there is a difference between references and objects. So this instruction say...
e1.e = e3;
The reference "e" in the object pointed to by e1 is assigned to the object pointed to by e3. After this operation, there is now two references pointing to the same object... both e1.e and e3 are now both referencing the same object.
In other words, e1.e is *not* referencing e3, it is referencing the same object that e3 is referencing.
After...
e3 = null;
the e3 reference is now no longer pointing to the object, but the e1.e reference still is.
Henry
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
SCJP1.5(81%), SCDJWS(94%), next mission SCEA (but need to wait or that)
SCJP1.5(81%), SCDJWS(94%), next mission SCEA (but need to wait or that)
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Does anyone have an explanation to my reply? When an object have instance reference variables and the reference of the object is set to null, does the objects that the instance reference variables refer to become eligible for GC (assuming no other reference variable refer to them)? I'm not sure if that made any sense
i want to know if object is elligible for GC?
Please if anyone could explain this will be kinda of you.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |