aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic
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
 
jQuery in Action, 2nd edition
 
subject: Garbage Collection