如何查看应用程序正在使用的当前堆大小? [英] How to view the current heap size that an application is using?

查看:190
本文介绍了如何查看应用程序正在使用的当前堆大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我增加了我的堆大小为1 GB的NetBeans,因为我改变了配置看起来是这样的:

I think I increased my heap size to 1 GB in NetBeans since I changed the config to look like this:

netbeans_default_options="-J-Xmx1g ......

重新启动NetBeans后,我能确定吗?我的应用程序现在是1 GB?

After I restarted NetBeans, can I be sure that my app is given 1 GB now?

有没有办法验证这个?

推荐答案

使用此代码:

// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory(); 

// Get maximum size of heap in bytes. The heap cannot grow beyond this size.// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();

 // Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory(); 

它是对我来说很有用t。

It was useful to me to know it.

这篇关于如何查看应用程序正在使用的当前堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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