We know that for any other objects GC will take care of deallocation. but what happens to a String objects which resides in String pool. who will decide it to deallocate and who actually does it? because we know that there will be String literals still present even after dereferencing it.
+2
A:
Strings that you don't hold a reference to anymore can be garbage collected, as the string pool most likely uses weak references, which are references to objects that can be garbage collected, and are invented exactly for this purpose (caches and the likes).
abyx
2010-01-19 16:03:38
A:
The string pool lives in the perm space. It will be garbage collected like every other generation.
If you run code like in this example it will fill up the perm space before the garbage collection kicks in. You won't see OutOfMemoryErrors as long as the internalized strings can be garbage collected.
Thomas Jung
2010-01-19 16:27:02