Empty infinite loop and GC (JVM). Please explain t

2019-06-18 07:41发布

My Empty infinity loop

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

And profiling in Java VisualVM (picture) Visual GC

As you can see, I do not create objects. Why change a heap?

Please explain the effect. Why?

1条回答
祖国的老花朵
2楼-- · 2019-06-18 08:41

Basically any Java application is multithreaded, the fact that your main thread does not allocate memory does not mean that the others do not allocate either. In fact it is very likely that by attaching via VisualVM and showing the GC tab you have spawned some threads in the VM to monitor GC resources and feed VisualVM the metrics that become those shiny charts. And that monitoring will likely allocate some resources of its own to do its job.

查看更多
登录 后发表回答