分析 JVisualVM 配置文件 - 查找大量原始类型的来源?
我正在尝试减少应用程序的内存占用。 JVisualVM 堆转储报告占用最多空间的对象是:
- char[]
- byte[]
- int[]
这并不是特别有用。我如何跟踪这些对象回到持有它们的父类?
谢谢
I am trying to reduce the memory footprint of my application. JVisualVM heap dumps report that the objects taking up the most space are:
- char[]
- byte[]
- int[]
Which isn't particularly helpful. How can I track these objects back to the parent classes that are holding them?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VisualVM 会计算保留大小。您必须手动添加该列,但默认视图似乎没有它。
VisualVM does compute retained size. You have to add the column manually, the default view doesn't seem to have it though.
这些原始数组可能是
String
之类的内部状态,它将其状态保存在char[]
中。一个好的分析器会理解这一点,并且会有“保留大小”的概念,它描述对象的大小,包括其子对象的大小。这表明String
占用了空间,而不是char[]
。但是,我在 VisualVM 中没有看到提到“保留大小”。它似乎不具备商业替代品的适当分析功能。
要了解我在说什么,请尝试下载 YourKit 的评估版,并将其连接到您的应用程序。它比 VisualVM 复杂得多,但它可以为您提供堆对象的保留大小,并且非常具有启发性。它还将向您显示引用堆上每个对象的内容,以便您可以跟踪泄漏。
Those primitive arrays are likely to be the internal state of things like
String
, which keeps its state in achar[]
. A good profiler will understand this, and will have the notion of "retained size", which describes the size of objects including the size of their sub-objects. This would indicate thatString
was taking up the space, notchar[]
.However, I see no mentioned of "retained size" in VisualVM. It doesn't seem to have the proper profiling capabilities of the commercial alternatives.
To see what I'm talking about, try downloading an evaluation of YourKit, and connect that to your app. It's a lot more complex than VisualVM, but it can give you the retained size of the heap objects, and it's quite illuminating. It will also show you what is referencing each of the objects on the heap, so you can trace leaks.