java有堆内存,可以通过-xms -xmx来进行控制,当然使用该参数控制的也只是堆内存.
1. 为什么启动tomcat后我设置的最大xmx为64,但实际可能占用128
原因:内存说明见下:
Heap Memory Pool: Non-Heap Memory Pool: 由上可知,jvm除占用堆内存外还占用了非堆内存,该非堆内存可能占用的和堆内存一样大.
2.非堆内存会垃圾回收吗?
可以:
Can the permanent generation be garbage collected?Yes it can. There is often the misconception that string constants cannot be garbage collected. However the only requirement that the JVM specification stipulates is that identity comparison works for constant string values. There is no requirement that the constant be the same object throughout the lifetime of the JVM. Hence if there are no references left to a string constant, there is no reason why it cannot be garbage collected. To prove this take the following code: public class PermGenDemo { public static void main(String[] args) { int i = 0; while (true) { ("string-" + ++i).intern(); } } } If the above code is run using the following command: $ java -verbose:gc -XX:PermSize=8m -XX:MaxPermSize=64m PermGenDemo The following output will be seen (note output cut for brevity): [Full GC [PSYoungGen: 32K->0K(28928K)] . . . [PSPermGen: 65535K->6461K(65536K)]] [Full GC [PSYoungGen: 32K->0K(31168K)] . . . [PSPermGen: 65535K->6461K(65536K)]] The above conclusively shows that the permanent generation is collected and when it requires collecting, triggers a full collection.
另有一张清晰的图可以说明:
3.非堆内存里面还有什么?
非堆内存里面还有code cache,正在研究如何控制他们. |
|