2

在跟踪可能的内存泄漏时,我遇到了以下现象。Java 7 回收实习字符串或 jmap 是否不精确?

# jmap -heap 9724 | grep 实习
正在附加到进程 ID 9724,请稍候...
调试器连接成功。
检测到服务器编译器。
JVM版本是23.3-b01
10526 个实习字符串,占用 880048 个字节。

# jmap -heap 9724 | grep 实习
正在附加到进程 ID 9724,请稍候...
调试器连接成功。
检测到服务器编译器。
JVM版本是23.3-b01
10514 个实习字符串,占用 878984 个字节。

# jmap -heap 9724 | grep 实习
正在附加到进程 ID 9724,请稍候...
调试器连接成功。
检测到服务器编译器。
JVM版本是23.3-b01
10519 个实习字符串,占用 879720 字节。

环境:Linux 版本 2.6.32-220.23.1.el6.centos.plus.x86_64 (mockbuild@c6b5.bsys.dev.centos.org) (gcc 版本 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC ) ) #1 SMP Tue Jun 19 04:14:37 BST 2012

java 版本“1.7.0_07”Java(TM) SE 运行时环境(构建 1.7.0_07-b10)Java HotSpot(TM) 64 位服务器 VM(构建 23.3-b01,混合模式)

4

1 回答 1

3

是的,Interned Strings 被回收。并且正如其中规定的那样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.

于 2013-03-26T19:31:42.227 回答