Empty infinite loop and GC (JVM). Please explain the effect

僤鯓⒐⒋嵵緔 提交于 2019-12-23 09:42:04

问题


My Empty infinity loop

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

And profiling in Java VisualVM (picture)

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

Please explain the effect. Why?


回答1:


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.



来源:https://stackoverflow.com/questions/13868693/empty-infinite-loop-and-gc-jvm-please-explain-the-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!