File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes is this object eligible for garbage collection?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is this object eligible for garbage collection??" Watch "is this object eligible for garbage collection??" New topic
Author

is this object eligible for garbage collection??

yuvraj kotegar
Ranch Hand

Joined: Jul 31, 2008
Posts: 120

is the object 's' eligible for garbage collection at line 3 ??
Venkata Kumar
Ranch Hand

Joined: Apr 16, 2008
Posts: 110

Yes.When the object has no references, in the given example when the end of the main() method is reached, then it is eligible for garbage collection.


SCJP 5.0, SCWCD 5, preparing for SCDJWS
Anoobkumar Padmanabhan
Ranch Hand

Joined: Aug 08, 2007
Posts: 103
Hi



I dont think the object referred by s will be available for GC at LINE3 because it has the refernce, s, now also. An object will be available for GC, when it don't have any live references.
In my opinion, it will be available for GC at LINE 4, ie, by the end of that method


Thanks<br /> <br />Anoobkumar<br />SCJP 1.5
Maya Dolas
Greenhorn

Joined: Jul 04, 2007
Posts: 26
An object is eligible for garbage collection when there is no direct or indirect reference to it.

In this case at Line 3 there is still a reference to the StringBuffer object. The object would be eligible for garbage collection when the program goes out of scope. If you want to make it eligible for GC before the main method goes out of scope make all the references to it null explicitly.


<b><i>Maya</i></b>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is this object eligible for garbage collection??