Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does JVM heap keep growing?

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

like image 618
Brian Avatar asked Feb 24 '15 06:02

Brian


1 Answers

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.

like image 143
Khanna111 Avatar answered Nov 15 '22 06:11

Khanna111