Why does JVM heap keep growing?

2019-03-19 07:39发布

I write a simple program and use jconsole.exe to monitor its heap size.

public class HeapTest {
    public static void main(String[] args) {
        while(true) {
        }
    }
}

Here is the result enter image description here

I don't understand why the heap size keeps growing. I don't new() any Object in my program.

What is the heap used for in my program?

I don't add any additional arguments to jconsole.exe; just double click on it, then load the java process according to PID.

Environment: Java 1.8.0_25 under windows 7

2条回答
地球回转人心会变
2楼-- · 2019-03-19 08:08

You can use JConsole alternative command jmap monitor java process, and you can find java heap size is stationary.

查看更多
▲ chillily
3楼-- · 2019-03-19 08:14

There is no memory leak here. Replicated it in OSX as well. It would be the book keeping data generated by the normal functioning of the VM including that for the GC. The eden goes up and once the GC occurs, the memory used by the heap (eden) is reduced and the cycle starts again.

The confusing aspect is that there are no objects being created explictly by the program but it would make sense to expound that the JVM would be doing so and hence the gradual increase in eden space till the next GC.

查看更多
登录 后发表回答