2

I am aware of string pool in java but how long does the string pool exists- till the jvm stops or when the class is unloaded .

i mean is it class specific or jvm specific . i saw another link for reference but that didnt clear up my doubt .

Community
  • 1
  • 1
jayendra bhatt
  • 1,337
  • 2
  • 19
  • 41
  • 1
    *"when the class is unloaded"* Which class? `String`? I don't think that language classes (`java.lang`), like `String`, will ever by unloaded since other background classes rely on them. – Tom Mar 07 '16 at 10:42
  • 1
    When the JVM exits *everything* is released. – user207421 Mar 07 '16 at 11:05
  • That answer clearly states that the string pool exists till the end of JVM life, while specific `String` object, which is stored there, may be GCed when corresponding class is unloaded and no more references are present to the object. – user3707125 Mar 07 '16 at 11:08
  • 2
    I have found this excellent blog post about the String pool : http://java-performance.info/string-intern-in-java-6-7-8/ – Arnaud Denoyelle Mar 07 '16 at 11:08
  • object are garbage collected when they are dereferenced . but the string present in string pool are self referenced(interned) hence cannot be gced. so are they availaible throughout till the jvm is alive ? – jayendra bhatt Mar 07 '16 at 11:11
  • 1
    @ArnaudDenoyelle Great read! I learned a thing-or-two about a thing-or-two. I'd also though that the strings couldn't be dereferenced until the JVM came down. – goodguy5 Mar 07 '16 at 13:36

1 Answers1

2

Since Java 7, String Pool is a pool of Strings stored in Java Heap Memory. So it means that String values on the pool are garbage collected when they become unreachable. If don't, they are available till the end of JVM life.

nnunes10
  • 550
  • 4
  • 14
  • 1
    String Pool is stored in heap since Java 7. Until Java 6, it was stored in the PermGen. (see http://java-performance.info/string-intern-in-java-6-7-8/ ) – Arnaud Denoyelle Mar 07 '16 at 11:07