This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java 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 Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "garbage collection " Watch "garbage collection " New topic
Author

garbage collection

vini singh
Greenhorn

Joined: Dec 04, 2008
Posts: 18
At what point only a single object is eligible for garbage collection?

class Eco
{
public static void main(String []args)
{
Eco e1=new Eco();
Eco e2=new Eco();
Eco e3=new Eco();
e3.e=e2;
e1.e=e3;
e2=null;
e3=null;
e1=null;
}

Eco e;

}


output is:Never in this program as until last refernce is null none of the objects is eligible and when last refernce is nulled all three are eleigible.

what is meant by last refernce.n xplain the output
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43423
    
  32
That exercise looks familiar; please quote Your Source. And please use the code button to preserve indentation and legibility.

When you get to the end of the method, work out which object the e1 reference points to, then work out what all its fields are, and whether they have any references. Write it on a sheet of paper and that ought to explain your problem.
Harvinder Thakur
Ranch Hand

Joined: Jun 10, 2008
Posts: 231
Vini,

IMHO, you will get prompt answers for such questions in SCJP forum

Anyways, let me try and explain it with a diagram:



Hope this helps clear the picture


thanks
Harvinder
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: garbage collection
 
It's not a secret anymore!