In the K&B
SCJP study guide book there is a question related to garbage collection. I have a doubt or you can say i have a question regarding the textbook answer so i need an explanation.
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
}
}
Question: When //doStuff is reached, how many objects are eligible for Garbage Collection ?
My answer is 3. The objects i think eleigible are c1, the Short object associated with c1 and c3.
But according to the book only 2 objects are eligible: c1 and the Short object associated with it.
So i need an explanation that 'Why is c3 not eligible for gc since it references a null object that it obtained from the method go'.
Thanks
Abhi