Hunter McMillen wrote:right, but the references to those literals can be collected. Sorry I shouldve mentioned that, thanks Fred.
No, the garbage collector only deals with objects. Variables (references to objects) are not objects themselves; the garbage collector doesn't clean up those.
Might be worth while reading this.
s begri wrote:we know that strings are located on the String constant pool
Only string literals and interned strings are located in the string pool. As Fred said these are not garbage collected. All other string objects are located in normal heap memory and are garbage collected the same way as other objects
Joanne Neal wrote:Only string literals and interned strings are located in the string pool.
actually the references of the string literals and interned strings are located in the string pool. always String objects are live in heap. and those references never removed by JVM, thus the objects which referenced by string constant pool are not eligible for Garbage Collection.