The same as every other object, once there are no more references to that object, it becomes eligible for garbage collection, I put that in bold because is doesn't guarantee that it will be collected, only that it could be collected.
Hunter
"If the facts don't fit the theory, get new facts" --Albert Einstein
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.
Thanks Hunter McMillen for your reply.
Actually we know that strings are located on the String constant pool , so after calling the GC what is happened ?
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.