• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection Question

 
Daniel Hernaez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to everybody, I am studying for my SCJP exam and this is my first post. Thanks in advance for your help.

My doubt refers to question #1 of chapter 3 self test (page 277).



The question is: When // doStuff is reached, how many objects are elegible for GC?

The correct answer is C. 2 objects are elegible for GC: c1 and its associated Short wrapper object.


Now, if I debug that code with Eclipse, I see that c3 object is also null due c1.go(c2) returns null. So, why isn't c3 also eligible for GC?


Thank you.
 
Jack Bento
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

c3 never pointed to an object. A total of 4 objects were created. 2 are available for gc and 2 are still referenced by c2.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do a search of the forum for cardboard, there have been many questions related to this particular question. Some of those responses may be of use to you.
 
Daniel Hernaez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, I didn't realise of that.

See you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic