• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection

 
vvus bharadwaj
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garage collector runs whenever an object is not in a reachable position.That can be achieived through disconnecting the link between object and reference variable.
I have a example.
Line1:Integer y=new Integer(567);
Line2:int x=y.intValue();
Line3:x++;
Line4:y=new Integer(x);
In the above example a new object is created at line1.We unwrap the primitive and modify the primitive value at line 2 and line3.At line4 another instance is created and assigned to same reference variable y.So now reference variable y points to new object.Then object created at line1 becomes eligible for garbage collection.Is this right?
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic