wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Ready for 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 "Ready for garbage collection" Watch "Ready for garbage collection" New topic
Author

Ready for garbage collection

Karin Paola Illuminate
Ranch Hand

Joined: Oct 18, 2002
Posts: 109
I've got a question about "http://www.java-help.com/Lesson16.htm".
An object is automatically "garbage collected" when it can no longer be referenced.
double x = new Double("123.45").doubleValue();
The Double object is never assigned to an object reference. At what moment will the Double object be ready for garbage collection?


I not only use all the brains that I have, but all that I can borrow. [Laurence J. Peter]
Jon Huhtala
Greenhorn

Joined: Apr 10, 2002
Posts: 17
Karin,
Technically the object that was constructed by the
new Double("123.45)
is "eligible" for garbage collection immediately after the statement is executed. There is no way to tell exactly when the JVM will dispose of the object. It does it when it is darn good and ready...


- Jon Huhtala, SCPJ2<p> "Nothing worthwhile is ever easy..."
ramki srini
Greenhorn

Joined: Aug 27, 2002
Posts: 26
double x = new Double("123.45").doubleValue();
If we take "123.45" as String literal, then I don't think it will be garbage collected anytime.
All String literal will be kept in the String pool and will be used by the JVM in all future references for the same literal.
I hope I am right, but I am not sure. Please correct me if I am wrong.
Regards
Ramki.
Jon Huhtala
Greenhorn

Joined: Apr 10, 2002
Posts: 17
Good point, Ramki. The string literal will remain but the Double object will be garbage collected.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ready for garbage collection
 
Similar Threads
Is this Memory Lekage?
object elligible for garbage collection
When does Connection Object is ready for Garbage Collection?
GC Question.
finishing a thread