Key concepts

Updated at:

This topic explains key concepts in Java heap analysis. These concepts appear throughout the analysis results, and understanding them is essential for interpreting the data.

Shallow size

The size of an object itself. For example, a long is 8 bytes and an int is 4 bytes.

Retained set

image.png

The retained set is the collection of objects that are also released when a specific object is released. In the graph above, for example, when object C is released, objects D, E, F, G, and H become unreachable. The retained set of object C is {D, E, F, G, H}. When object C is released, the objects in its retained set are also released.

Retained size

The retained size of an object is the total size of all objects in its retained set. In the example graph, the retained size of C = size of D + size of E + size of F + size of G + size of H. In other words, the retained size is the amount of heap space that is freed when the object is released. This is an important metric.

Dominator tree

This is a concept from graph theory often used to construct the control flow in compilers. In heap analysis, an object A dominates an object B if every path to B must pass through A. A dominator tree is an object graph built on this dominance relationship. For example, in the graph above, every path to object E must pass through C. Therefore, C dominates E. However, a path to H does not have to pass through G, because a path also exists through F. Therefore, G does not dominate H.

GC Root

GC Roots are objects in specific regions from which the garbage collector starts scanning for live objects. For example, in the graph below, the garbage collector starts from the thread stack area, finds objects A and B, and then uses these two objects as starting points to scan for other objects.

image.png

GC Root path

A GC Root path is the chain of references from a GC Root to a specific object. For example, the GC Root path for object C is A->B->C. The garbage collector follows these paths starting from a GC Root to find all live objects. As long as a GC Root path to an object exists, the object is considered live and is not released. This path also explains why an object is retained in memory. An object that is eligible for garbage collection does not have a GC Root path. An object can have multiple GC Root paths.