How to print the whole String pool?

后端 未结 2 1443
不知归路
不知归路 2020-11-27 20:16

I wanted to print the whole string pool which contains literals and String objects added using intern() just before garbage collection.

Is

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 20:50

    http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#finalize%28%29 , So the GC calls finalize method before clean-up any of the objects.

    So the finalize method in String is also getting called. But sadly String is a final class and you cannot override it. (Why is String class declared final in Java?)

    But If you really want to get this thing to be worked, then you need to create your own string object named something else, but inner behaviour will keep all the strings functions.

    And for a guaranteed GC try this : http://code.google.com/p/jlibs/wiki/GarbageCollection

提交回复
热议问题