在追踪可能的内存泄漏时,我发现了以下现象。 Java 7 回收 interned Strings 或 jmap 不精确吗?
# jmap -heap 9724 | grep interned Attaching to process ID 9724, please wait... Debugger attached successfully. Server compiler detected. JVM version is 23.3-b01 10526 interned Strings occupying 880048 bytes. # jmap -heap 9724 | grep interned Attaching to process ID 9724, please wait... Debugger attached successfully. Server compiler detected. JVM version is 23.3-b01 10514 interned Strings occupying 878984 bytes. # jmap -heap 9724 | grep interned Attaching to process ID 9724, please wait... Debugger attached successfully. Server compiler detected. JVM version is 23.3-b01 10519 interned Strings occupying 879720 bytes.
环境: Linux 版本 2.6.32-220.23.1.el6.centos.plus.x86_64 ( [email protected] ) (gcc 版本 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP 2004 年 6 月 19 日星期二: 2012 年英国夏令时 14:37
java版本“1.7.0_07” Java(TM) SE 运行时环境(版本 1.7.0_07-b10) Java HotSpot(TM) 64 位服务器 VM(内部版本 23.3-b01,混合模式)
最佳答案
是的,内部字符串被回收。并如 Java SE 7 Features and Enhancements
中指定。建议:
In JDK 7, interned strings are no longer allocated in the permanent generation of the Java heap, but are instead allocated in the main part of the Java heap (known as the young and old generations), along with the other objects created by the application. This change will result in more data residing in the main Java heap, and less data in the permanent generation, and thus may require heap sizes to be adjusted. Most applications will see only relatively small differences in heap usage due to this change, but larger applications that load many classes or make heavy use of the String.intern() method will see more significant differences.
关于java - Java 的 interned 字符串会被 GC 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15645408/