So I'm just reading about the
String pool on page 419/420 of the K&B book and I have a question.
Do un-referenced elements in the String pool get garbage collected just like any other object?
The reason I ask is that if elements in the String pool get GC'ed shortly after they become unreachable, wouldn't that reduce the efficiency of the String pool?
On the other hand, if the String pool is never flushed of unused Strings, it could get very big indeed.
So in practice, are Strings in the String pool just like any other object from a GC point of view, or do they get some kind of special treatment? (e.g. does the GC only go after the String pool if it has exhausted all other options?)
From what it says on p420 about forcing a new String object using new String("my new string");, I take it that Strings made this way are definitely treated as normal objects, since they are allocated outside of the String pool?
I'd be very grateful if someone could clear that up for me. Thanks.
Andy