wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collection" Watch "Garbage collection" New topic
Author

Garbage collection

vvus bharadwaj
Ranch Hand

Joined: Apr 28, 2012
Posts: 38
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

Joined: Feb 26, 2005
Posts: 2049
Yes, you are right.
 
 
subject: Garbage collection
 
Similar Threads
eligible for garbage collection
Doubt in Garbage Collection
Overloading doubt
gc
explain the output - constructors