• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection problem??

 
Ravinder Rana
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i think 2 objects r eligible 4 garbage collection(at line 4).

I'm a bit confuse,plz explain this garbage collection regarding in method return.



Thanks in advance.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only one object.

3. X x = new X(); //create one. x references to it
4. X x2 = m1(x); //create one in m1 method. x2 references to it
5. X x4 = new X(); //create one. x4 references
6. x2 = x4; //x2 references to x4's object. x2 originally referenced object can be GC.
 
Ravinder Rana
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks 4 reply,
Wise Owen u r saying, X x=new X();//creat one
I think it creates two objects, then how one object eligible 4 garbage colln.

Plz clear it to me, I'm a bit confuse.



Thanks in advance.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many instances of X are created from line 3 to 5?
Can you explain why u think 2 objects 4 GC?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic