permaculture playing cards
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC question (K&B SCJP 6) 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 "GC question (K&B SCJP 6)" Watch "GC question (K&B SCJP 6)" New topic

GC question (K&B SCJP 6)

Sajesh Adulkar

Joined: Sep 18, 2011
Posts: 7
I need help to understand why object c3 and its Wrapper object will not be eligible for GC in the following question:

class CardBoard {
Short story = 200;
CardBoard go(CardBoard cb) {
cb = null;
return cb;
public static void main(String args[]) {
CardBoard c1 = new CardBoard();
CardBoard c2 = new CardBoard();
CardBoard c3 = c1.go(c2);
c1 = null;

c3 is indeed set to null so why is it not eligible? (As I understand c2 is not eligible because of return cb; in go()...right?)
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

To make it Simple...

Your Question's Equivalent one is

In the above code as far as i know "c3 is Garbage Collectible ".

only if you do...

Then C3 is NOT garbage Collectible

(Born to Win)
Sajesh Adulkar

Joined: Sep 18, 2011
Posts: 7
Thank you, your explanation clarifies what is happening.
I agree. Here's the link:
subject: GC question (K&B SCJP 6)
It's not a secret anymore!