Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection doubt" Watch "Garbage Collection doubt" New topic
Author

Garbage Collection doubt

mamidi venkat
Ranch Hand

Joined: Jul 03, 2007
Posts: 63
Hi All

X3 x2 = new X3();
X3 x3 = new X3();
X3 x5 = x3;
x3 = x2;
X3 x4 = x3;

Question
x5->x3
x3->x2

Can any one explains me what happens with x5 here is x5 is deleted
because x3 having the reference of x2 or x5 is holding the reference of x3



Kishore Kumar
Ranch Hand

Joined: Oct 15, 2007
Posts: 71
Here None of the object is garbage collected.

x5 is pointing to the object which was created by x3 reference previously.
mamidi venkat
Ranch Hand

Joined: Jul 03, 2007
Posts: 63
Thanks for reply

i want to know one thing cleary objects are eligible for the garbage collection.what about object reference and static members

x5->x3
x3->x2
x5=null

now x5 is elibigle for the GC right
Kishore Kumar
Ranch Hand

Joined: Oct 15, 2007
Posts: 71
Yes object refered by x5 is eligible for Garbage Collection.
mamidi venkat
Ranch Hand

Joined: Jul 03, 2007
Posts: 63
Thanks for reply

i want to know one thing cleary objects are eligible for the garbage collection.
what about object reference and static members ???
 
Consider Paul's rocket mass heater.
 
subject: Garbage Collection doubt