Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Question 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 "Garbage Collection Question" Watch "Garbage Collection Question" New topic

Garbage Collection Question

Daniel Hernaez

Joined: Feb 15, 2010
Posts: 9
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

Joined: Jun 14, 2009
Posts: 34
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

Joined: Feb 10, 2009
Posts: 710
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.

When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Daniel Hernaez

Joined: Feb 15, 2010
Posts: 9
Thanks a lot, I didn't realise of that.

See you.
I agree. Here's the link:
subject: Garbage Collection Question
It's not a secret anymore!