空无限循环和GC(JVM).请说明效果 [英] Empty infinite loop and GC (JVM). Please explain the effect

查看:80
本文介绍了空无限循环和GC(JVM).请说明效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的空无限循环

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

并在Java VisualVM中进行概要分析(图片)

And profiling in Java VisualVM (picture)

如您所见,我没有创建对象.为什么要换堆?

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

请说明效果.为什么?

推荐答案

基本上任何 Java应用程序都是多线程的,您的主线程没有分配内存这一事实并不意味着其他线程没有分配内存任何一个.实际上,很可能通过VisualVM附加并显示GC选项卡,您在VM中产生了一些线程来监视GC资源并向VisualVM提供成为那些闪亮图表的指标.而且该监视可能会分配一些自己的资源来完成其工作.

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.

这篇关于空无限循环和GC(JVM).请说明效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆