Shallow Size 和 Retained Size

简介:
所有包含Heap Profling功能的工具(MAT, Yourkit, JProfiler, TPTP等)都会使用到两个名词,一个是Shallow Size,另一个是 Retained Size. 
这是两个在平时不太常见的名词,本文会对这两个名词做一个详细的解释。 

Shallow Size  
对象自身占用的内存大小,不包括它引用的对象。 
针对非数组类型的对象,它的大小就是对象与它所有的成员变量大小的总和。当然这里面还会包括一些java语言特性的数据存储单元。 
针对数组类型的对象,它的大小是数组元素对象的大小总和。 

Retained Size  
Retained Size=当前对象大小+当前对象可直接或间接引用到的对象的大小总和。(间接引用的含义:A->B->C, C就是间接引用) 
换句话说,Retained Size就是当前对象被GC后,从Heap上总共能释放掉的内存。 
不过,释放的时候还要排除被GC Roots直接或间接引用的对象。他们暂时不会被被当做Garbage。 

看图理解Retained Size  

 

上图中,GC Roots直接引用了A和B两个对象。 

A对象的Retained Size=A对象的Shallow Size 
B对象的Retained Size=B对象的Shallow Size + C对象的Shallow Size 

这里不包括D对象,因为D对象被GC Roots直接引用。  
如果GC Roots不引用D对象呢? 

 


此时, 

B对象的Retained Size=B对象的Shallow Size + C对象的Shallow Size + D对象的Shallow Size

本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/p/3694924.html如需转载请自行联系原作者


demoblog

相关文章
|
3月前
【Simulink】报错:Size mismatch (size [2 x 1] ~= size [1 x 1]). The size to the left is the size of the l
【Simulink】报错:Size mismatch (size [2 x 1] ~= size [1 x 1]). The size to the left is the size of the l
|
8月前
|
索引
Result window is too large, from + size must be less than or equal to: [10000]
Result window is too large, from + size must be less than or equal to: [10000]
65 0
|
10月前
|
数据格式
batch_size的探索
batch_size的探索
57 0
|
10月前
|
数据格式
详解torch.size
详解torch.size
113 0
详解torch.size
|
11月前
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
652 0
|
11月前
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
694 0
|
PyTorch 算法框架/工具
pytorch报错 RuntimeError: The size of tensor a (25) must match the size of tensor b (50) at non-singleton dimension 1 怎么解决?
这个错误提示表明,在进行某个操作时,张量a和b在第1个非单例维(即除了1以外的维度)上的大小不一致。例如,如果a是一个形状为(5, 5)的张量,而b是一个形状为(5, 10)的张量,则在第二个维度上的大小不匹配。
3073 0
malloc(): corrupted top size
malloc(): corrupted top size
590 0
|
人工智能 C++ Python
LeetCode 961. N-Repeated Element in Size 2N Array
LeetCode 961. N-Repeated Element in Size 2N Array
169 0