JAVA Shallow heap & Retained heap, javashallowheap
I recently studied the memory leakage problem and found Shallow heap & Retained heap in the MAT tool.
Then I found some information on the Internet.
Shallow Size
The memory size occupied by the object itself, excluding the objects referenced by the object.
For non-array objects, its size is the sum of the size of the object and all its member variables. Of course, there will also be some data storage units with java language features.
For an array object, its size is the total size of the array element object.
Retained Size
Retained Size = Current object Size + total Size of objects that can be directly or indirectly referenced by the current object. (Meaning of indirect reference: A-> B-> C, C is indirect reference)
In other words, the Retained Size is the total memory that can be released from the Heap after the current object is GC.
However, objects directly or indirectly referenced by GC Roots must be excluded during release. They will not be treated as Garbage for the moment.
Retained Size
.
Retained Size of object A = Shallow Size of object
Retained Size of object B = Shallow Size of object B + Shallow Size of Object C
The D object is not included here, because the D object is directly referenced by GC Roots.
What if GC Roots does not reference the D object?
At this time,
Retained Size of object B = Shallow Size of object B + Shallow Size of Object C + Shallow Size of object D