File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ready for garbage collection

 
Karin Paola Illuminate
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jon Huhtala
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
ramki srini
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic