Shallow vs. Retained Heap
Shallow heap is the memory consumed by one object. An object needs 32 or 64 bits (depending on the OS architecture) per reference, 4 bytes per Integer, 8 bytes per Long, etc. Depending on the heap dump format the size may be adjusted (e.g. aligned to 8, etc...) to model better the real consumption of the VM.
Retained set of X is the set of objects which would be removed by GC when X is garbage collected.
Retained heap of X is the sum of shallow sizes of all objects in the retained set of X, i.e. memory kept alive by X.
Generally speaking, shallow heap of an object is its size in the heap and retained size of the same object is the amount of heap memory that will be freed when the object is garbage collected.
The retained set for a leading set of objects, such as all objects of a particular class or all objects of all classes loaded by a particular class loader or simply a bunch of arbitrary objects, is the set of objects that is released if all objects of that leading set become unaccessible. The retained set includes these objects as well as all other objects only accessible through these objects. The retained size is the total heap size of all objects contained in the retained set.
The Minimum Retained Size gives a good (under)estimation of the retained size which is calculated ways faster than the exact retained size of a set of objects. It only depends on the number of objects in the inspected set, not the number of objects in the heap dump.
注意:Retained Set 中包含的objects必须满足only accessible by Leading Sets.也只有满足仅被Leading Set引用,在Leading Set被释放的时候,其Retained Set也就可以被GC回收。如上图,H就不属于E的Retained Set,因为它同时被F引用。