堆内存与对象内存 [英] Heap memory vs object memory

查看:123
本文介绍了堆内存与对象内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据一篇关于Java内存和特性的论文:

According to a paper about Java memory and characteristics:


... 内存分数分为两种类型:堆内存,即运行时应用程序消耗的内存,以及对象内存,它是程序中使用的各种对象分配的内存,如整数和字符串等。 ...

当他们说对象内存时,他们是指堆栈内存,还是他们是什么意思? (混淆了,如果我没有错,用Java在堆中分配对象)

Do they mean the stack memory when they say object memory, or what do they mean? (confused since, if I am not wrong, objects are allocated in the heap in Java)

第二个问题,如果我只是想测量堆的总大小和在完整程序执行期间堆栈,我应该使用什么工具?我一直在环顾四周,尝试了 NetBeans 7.3.1 中的内置Java Profiler以及 YourKit 12.0.6 ,在那里我可以检查堆,但是学习对象和放在堆栈上的变量,我找不到办法!

Second question, if I simply want to measure the total size of the heap and stack during a full program execution, what tool should I use? I have been looking around and tried out the built-in Java Profiler in NetBeans 7.3.1 and also YourKit 12.0.6, where I am able to inspect the heap but when it comes to studying "objects" and variables placed on the stack, I can not find a way!

总结一下,我该如何衡量论文的描述:

To sum up, how do I measure what the paper is describing:


  • 使用的总堆内存

  • 使用的总对象内存

谢谢!

推荐答案

堆内存 :Java对象的存储。假设您使用new关键字创建类的实例。

Heap Memory : storage for Java objects. Say when you use new keyword to create an instance of a class.

堆栈内存:用于存储局部变量,方法调用等。 JVM还可以决定并使用它来存储某些对象以提高性能。

Stack Memory : used to store local variables, method call, etc. JVM also can decide and use it to store certain objects for performance.

要获得,你使用的总内存 -

To get, total memory you used-

usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

您无法在运行时获得堆栈内存,但您可以启动具有预定义堆栈大小的应用程序,具体取决于您的平台。

You cannot get stack memory on runtime but you can start an app with predefined stack size which depends on your platform.

有一个非堆内存,我认为它们定义为对象内存,用于存储加载的类......元数据等。

There's a non-heap memory which I think they defined as object memory which is used to store loaded classes..metadata, etc.

参考文献:

MemoryMXBean

JConsole

这篇关于堆内存与对象内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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