JVM内存中特定对象的子树的大小 [英] Size of the specific object's subtree in the JVM memory

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

问题描述

是否可以以编程方式检查一些对象占用多少内存(使用JVM内存中的整个子树)。我想说(来自java代码)

Is it possible to check programatically how much memory takes some object (with the whole subtree in the JVM memory). I would like to say (from the java code)


'告诉我当前JVM中有多少内存将JPanel带到
整个引用子树,当我们假设提到的JPanel是这棵树的根
时。

'tell me how much memory in the current JVM takes the JPanel with the whole reference subtree when we assume that mentioned JPanel is the root of this tree'.

我想知道我是不是这样可以比较两个JPanels(或JFrame或其他)需要多少内存,而且需要更多内存 - 而不分析转储。而且我想知道答案是否为'是'这个值的准确程度如何。

I wonder if I could this way compare how much memory take two JPanels (or JFrame or whatever), and which takes more - without analyzing the dump. And I wonder if the answer is 'yes' how precise would be this value.

推荐答案

如你的qustion评论中所述,java中的sizeOf问题不容易解决,不仅因为你试图调整大小的对象实际上不是内存图的根,而且还因为计算静态字段的大小等问题(它们属于整个类) ,不是任何具体的例子。)

as stated in the comments to your qustion, the sizeOf problem in java isnt easy to solve, not only because the object youre trying to size isnt really the root of a memory graph, but also because there are issues with counting the size of static fields etc (they belong to the whole class, not any specific instance).

然而,有办法获得一些有意义的数据。

however, there are ways to get some meaningful data.

第1方法是使用附加到jvm的java代理,后者又调用大小估计函数,sun / oracle从java 6开始添加。参见这个页面的说明

the 1st approach is to use a java agent attached to the jvm which in turn calls a size estimation function that sun/oracle have added starting with java 6. see this page for instructions

第二种方法是估计一个物体的大小t ree基于理论计算。有一个图书馆为您执行此操作此处

the 2nd approach is to estimate the size of an object tree based on theoretical calculations. there's a library that does this for you here

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

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