File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC question (K&B SCJP 6)

 
Sajesh Adulkar
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
//System.out.println(c3);
//System.out.println(c3.story);
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
Posts: 196
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sajesh Adulkar
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, your explanation clarifies what is happening.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic