| Author |
GC question (K&B SCJP 6)
|
Sajesh Adulkar
Greenhorn
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);
//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
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
|
KARTHICK.C , SCJP6-93%
(Born to Win)
|
 |
Sajesh Adulkar
Greenhorn
Joined: Sep 18, 2011
Posts: 7
|
|
|
Thank you, your explanation clarifies what is happening.
|
 |
 |
|
|
subject: GC question (K&B SCJP 6)
|
|
|