Originally posted by Ajith Kallambella:
String literals( string objects that are not new'd ) are a part of the constant string pool that is maintained on a per-class basis. Unlike the objects that are created on the heap which gets garbage collected using a "no-active-reference" logic, the objects in the constant pool are not GC'd until the class gets unloaded.
The JVM spec suggests, but not mandates, that the constant runtime pool for all classes be cleaned up when the class is unloaded by the JVM. However, since this is not a must-have feature, there are several implmentations of VM which ignores this requirement leaving behind many unclaimed objects.
FYI, there are some implementations of VM that are written for typically small devices such as wireless phones or PDAs, where memory is an expensive resource, that actually follow this requirement and sweep even the constant runtime pool before unloading the class.
You may want to checkout the VM spec about the details of the constant runtime pool incase you are curious.
Hope that helps