Why does JVM heap keep growing?

前端 未结 3 451
-上瘾入骨i
-上瘾入骨i 2021-02-08 18:52

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)          


        
相关标签:
3条回答
  • 2021-02-08 19:18

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

    0 讨论(0)
  • 2021-02-08 19:20

    you've assumed that main( ) is your only thread, which is an incorrect assumption. There are other threads that will allocate objects

    0 讨论(0)
  • 2021-02-08 19:31

    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.

    0 讨论(0)
提交回复
热议问题