YourKit-对象的保留大小不等于其引用的所有对象的保留大小 [英] YourKit - The retained size of an object doesn't equal the retained size of all the objects referred by it

查看:82
本文介绍了YourKit-对象的保留大小不等于其引用的所有对象的保留大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对象的保留大小不等于其引用的所有对象的保留大小.

The retained size of an object doesn't equal the retained size of all the objects referred by it.

这是正在发生的事情:

  1. 使用YourKit捕获内存快照.
  2. 点击一个对象&按类类型显示实例
  3. 假设实例的保留内存为A字节(600mb)
  4. 扩展并求和基础实例的保留大小,假设总和为B(300mb)

A >> B

推荐答案

让我举个例子.

首先,您需要了解什么是保留大小. 从官方文档:

First of all, you need to understand what retained size is. From the official documentation:

保留尺寸是对象的浅尺寸加上浅尺寸 只能直接或间接访问的对象 这个对象.换句话说,保留的大小代表金额 此对象将由垃圾收集器释放的内存量 被收集.

Retained size of an object is its shallow size plus the shallow sizes of the objects that are accessible, directly or indirectly, only from this object. In other words, the retained size represents the amount of memory that will be freed by the garbage collector when this object is collected.

简单地说,对象的保留大小实际上就是该对象所引用的对象的总和.在下面的图片中,Obj1的保留大小是Obj1浅大小以及Obj2和Obj3保留大小的总和:

In a simple the retained size of an object will indeed be the sum of the objects referred by it. In the picture below the retained size of Obj1 is the sum of the Obj1 shallow size, and Obj2 and Obj3 retained size:

在更复杂的引用模型中不是这种情况.如果Obj6开始引用Obj5,则不能仅从Obj2访问Obj5.因此,保留的Obj2大小现在将仅包括Obj4,并且将不包括Obj5. Obj1的保留大小将保持不变.如果垃圾回收器释放了Obj1,它将释放大小为41的整个引用图. 但是,如果垃圾收集器仅释放Obj2,则不会释放Obj5,因为Obj6仍会引用它.

This is not the case in more complicated referencing models. If Obj6 starts referencing Obj5, then Obj5 will not be accessible only from Obj2. So the retained size of Obj2 will now include only Obj4, and will exclude Obj5. The retained size of Obj1 will stay the same. If garbage collector frees Obj1, it'll free the whole references graph of size 41. However, if garbage collector frees only Obj2, it will not free Obj5, because it would be still referenced by Obj6.

这篇关于YourKit-对象的保留大小不等于其引用的所有对象的保留大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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