*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dans Questions : GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dans Questions : GC" Watch "Dans Questions : GC" New topic
Author

Dans Questions : GC

Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97

Which of the three objects, A, B or C, is not eligible for garbage collection when method m2 begins to execute?
a. A
b. B
c. C
d. None of the above
Answer is C... I thought every object is eligible for GC after the method has finished (in this case method m1) ???
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
The answer given is correct, "A" looses its reference when (i1 = i3) is executed and "B" looses its reference when i2 = i3 is executed, the remaining object is "C" which has three references on it (i1, i2, i3).
Note also that "A", "B" and "C" are member objects, they'll loose their reference only after new J().m1(); finishes, executing m2() has no effect at all.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
 
GeeCON Prague 2014
 
subject: Dans Questions : GC