| Author |
Garbage Collection
|
radhika holani
Greenhorn
Joined: Mar 28, 2006
Posts: 29
|
|
1. class X2 { 2. public X2 x; 3. public static void main(String [] args) { 4. X2 x2 = new X2(); 5. X2 x3 = new X2(); 6. x2.x = x3; 7. x3.x = x2; 8. x2 = new X2(); 9. x3 = x2; 10. doComplexStuff(); 11. } 12. } after line 9 runs, how many objects are eligible for garbage collection? A. 0 B. 1 C. 2 D. 3 E. 4 Can anyboby tell me what is the right answer for this and why?
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
hi Answer is C Objects created at Line 4 & 5 are eligible for GC,it forms Island of Isolation.No reference from outside.
|
 |
Amit Goyal
Ranch Hand
Joined: Feb 21, 2006
Posts: 95
|
|
|
UR right vidya sagar, ans should be 'c'.
|
 |
radhika holani
Greenhorn
Joined: Mar 28, 2006
Posts: 29
|
|
|
can u tell me what is "Island of Isolation"
|
 |
Kristian Perkins
Ranch Hand
Joined: Mar 27, 2006
Posts: 32
|
|
|
This topic has been addressed a few times in this forum, here is one of the latest (which includes back links to even more discussions on it).
|
 |
radhika holani
Greenhorn
Joined: Mar 28, 2006
Posts: 29
|
|
thank u very much Kristian I got the point now
|
 |
 |
|
|
subject: Garbage Collection
|
|
|