Shallow and retained heap
An explanation of terms that relate to the Java™ heap.
The following terms are used to describe objects in the Java heap:
- Shallow heap
- The amount of memory that is consumed by one object. An object requires different amounts of memory depending on the operating system architecture. For example, 32 bits or 64 bits for a reference, 4 bytes for an integer, or 8 bytes for an object of type "Long". Depending on the heap dump format, the size might be adjusted to provide a more realistic consumption of the JVM.
- Retained set
- One or more objects plus any objects that are referenced, directly
or indirectly, only from those original objects. The retained set
is the set of objects that would be removed by garbage collection
when an object, or multiple objects, is garbage collected. The following diagram represents objects in the Java heap. Objects A and B are garbage collection roots, for example method parameters, locally created objects, or objects that are used for wait(), notify(), or synchronized() methods. The set of objects A and B has a retained set consisting of objects A, B, C, D, E, F, G, and H.If, for example, object G was referenced by a garbage collection root other than A or B, then object G would remain if objects A and B were removed during garbage collection. Object G would therefore not be in the retained set of objects A and B.

- Retained heap, or retained size
- The total heap size of all the objects in the retained set. This value is the amount of memory that is consumed by all the objects that are kept alive by the objects at the root of the retained set.
In general terms, the shallow heap of an object is the size of the object in the heap. The retained size of the same object is the amount of heap memory that is freed when the object is garbage collected.
The Calculate Minimum Retained Size pop-up menu option provides a good estimation of the retained size, and is calculated faster than the exact retained size of a set of objects. The minimum retained size depends only on the number of objects in the inspected set, not the number of objects in the heap dump.