简体   繁体   English

如何在JVisualVM的堆转储中计算“大小”

[英]How is “Size” calculated in JVisualVM's Heap Dump

I'm running Java Visual VM to analyze performance on a Mule app to reduce the amount of memory used. 我正在运行Java Visual VM以分析Mule应用程序上的性能,以减少使用的内存量。 When I look at the heap dump, I see that char[] has a size of over 37 MB, String has a size of a bit over 28 MB. 当我查看堆转储时,我发现char []的大小超过37 MB,String的大小超过28 MB。

What I'm not clear on is how the size column accounts for the amount of memory used. 我不清楚的是size列如何说明已使用的内存量。 In particular, since a String is an abstraction of a char[], I'm wondering if this means that some of that 37 MB of char arrays is also present within the 28 MB of Strings, or if they are allocated separately. 特别是,由于String是char []的抽象,所以我想知道这是否意味着28 MB的String中也存在37 MB的char数组中的一部分,或者它们是否单独分配。

On top of that, I also have a class that I suspect is hogging a great deal of memory and contains several strings, but according to my heap dump, this class only uses 6.5% of the total memory in the heap. 最重要的是,我还有一个我怀疑正在占用大量内存并包含多个字符串的类,但是根据我的堆转储,此类仅使用堆中总内存的6.5%。

So I guess my question is... If I were to make my custom class more efficient by using fewer String objects, would I see a reduction in the amount of memory reported to be used by Strings and Char[]s, or just for that specific class? 所以我想我的问题是...如果我想通过使用更少的String对象来提高自定义类的效率,我会发现报告的Strings和Char [] s使用的内存量减少了,还是仅用于那个特定的班级?

Thanks! 谢谢!

Holger's comment is all I needed... 我只需要霍尔格的评论...

"The sizes only include the memory for an object itself, not any referenced object (and arrays are objects)." “大小仅包括对象本身的内存,不包括任何引用的对象(数组是对象)。”

This alone gives me a much better idea of how I can optimize. 仅此一项就使我对如何进行优化有了更好的了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM