Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dans Questions : GC

 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic