File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collection" Watch "Garbage collection" New topic

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();
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: 2068
Yes, you are right.
I agree. Here's the link:
subject: Garbage collection
It's not a secret anymore!