SHALLOW, RETAINED, AND DEEP OBJECT SIZES
The shallow size of an object is the size of the object itself. If the object contains a reference to another object, the 4 or 8 bytes of the reference is included, but the size of the target object is not included.
The deep size of an object includes the size of the object it references. The difference between the deep size of an object and the retained memory of an object lies in objects that are otherwise shared.
Objects that retain a large amount of heap space are often called the dominators of the heap.
|8 (on 32-bit Windows JVMs, 4)|
The reference type here is the reference to any kind of Java object—instances of classes or arrays. That space is the storage only forthe reference itself. The size of an object that contains references toother objects varies depending on whether we want to consider theshallow, deep, or retained size of the object, but that size also includessome invisible object header fields. For a regular object, the size of theheader fields is 8 bytes on a 32-bit JVM, and 16 bytes on a 64-bit JVM(regardless of heap size).For an array, the size of the header fields is 16 bytes on a 32-bit JVM ora 64-bit JVM with a heap of less than 32 GB, and 24 bytes otherwise.