Nasir is right, though references to pool objects are the only way to refere to them but gc does not bother to collect objects in the pool. Reason?: String Pool is meant be small in size, just a way to optimize string literals, to be used here and there vide references. Therefore they are not suppose create a major threat to resources.
This conclusion is based on a simple expriement:
Made two
java files, one containing 1000 non-similar String literals and the other containing 1000 Strings created with new statement. Both were with same skeleton and both executed System.gc(I used another java application to create these two files, I'll post it if you'll need it). compiled and ran both under two instances of JVM with -verbose:gc (makes gc to report its efforts after garbage collection). The result spoke for itself: No memory recovery in the case of String literals and ofcourse gc recovered some 360K in the case of new String.
[This message has been edited by Amond Adams (edited December 02, 2000).]
[This message has been edited by Amond Adams (edited December 02, 2000).]
[This message has been edited by Amond Adams (edited December 02, 2000).]