• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Garbage collection & string literal pool

 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I am over it too.

These are my conclusions:



For your sake, can you please tell me where you think this "Pool String" lives? ...and how did you conclude that objects that are created for String literals are never garbage collected?



Strings literals can be garbage collected if and only the class loader which loaded their String class is garbage collected. This will only happen if your code do not have any other String object declared whose class is loaded by the bootstrap loader.



Prove that X.s and Y.s can refer to two different instances during runtime.
It can be done. Note that both are compile-time constant expressions (JLS 15.28) and so are inlined at compile-time.



They can refer to two different instances if they are loaded by a different class loader as long as a bootstrap class loader or any other loader have not loaded a string literal like the ones contained in X and Y.

So it is not true what I said that String literals are never garbage collected, altough it was true in the context of the initial post.

I did not changed my mind regarding the existance of the String pool and still do not know why you clamied the JLS was erroneous in that point. Yet I see the string pool as an array of references to String objects in memory. I think I never said they were not in memory.
[ February 02, 2005: Message edited by: Edwin Dalorzo ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A String literal is not garbage collected, since it is a String literal, not an object. It is the object that represents the String literal that is garbage collected.

The answer to your original question is b) as per my original post.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic