• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from K&B - pl clarify

 
jibs parap
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the question from K&B of chapter 3.
-------------------
class CardBoard {
Short story = 5;
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;
// do Stuff
} }
When // doStuff is reached, how many objects are eligible for GC?
---------
My thinking was the objects associated to c1 and c3 are eligible. Considering the Short wrapper object associated with each of them, there should be 4 objects eligible for GB.
Obviously, the answer is wrong. Can you explain whats wrong in my understanding please?

Thanks
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Discussed earlier


Thanks,
 
jibs parap
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers mate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic