This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dans Questions : GC" Watch "Dans Questions : GC" New topic

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!!!
I agree. Here's the link:
subject: Dans Questions : GC
jQuery in Action, 3rd edition