File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
radhika holani
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UR right vidya sagar, ans should be 'c'.
 
radhika holani
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can u tell me what is "Island of Isolation"
 
Kristian Perkins
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank u very much Kristian
I got the point now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic