Forums Register Login
is Strings in Java are not garbage-collected ?
Strings are stored in special "String Pool" which is not garbage-collected, ever. So all discarder string will sit there, wasting memory live zombies, never alive and never destroyed. Please tell me it is true.

Arpit: Strings are stored in special "String Pool"

References to strings literals are stored in the constants pool of every class. String objects themselves exist in the heap as any other object.

Arpit:which is not garbage-collected, ever.

Well not completely true. The string constants can be garbage collected if there are no references to them(like any other object). Since on garbage collection of the class definition, the constant pools will also be garbage collected, so, there can be a situation when a string literal is not referenced from anywhere and thus will be gc'ed.

This is an FAQ entry for your reference.

This thread has been viewed 746 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 11, 2018 22:19:40.