Developers are more
concerned about the size of objects when they are created. Eclipse memory
analyzer gives us information about the size of the object in 2 calculations.
Shallow Heap
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.
Shallow size of an
object is the amount of allocated memory to store the object itself, not taking
into account the referenced objects
Retained size of an
object is its shallow size plus the shallow sizes of the objects that are
accessible, directly or indirectly, only from this object. In other words, the
retained size represents the amount of memory that will be freed by the garbage
collector when this object is collected
Dead objects are
shown only with shallow size, as they do not actually retain any other objects.
Generally speaking,
shallow size of an object is its "flat" size in the heap whereas the
retained size of the same object is the amount of heap memory that will be
freed when the object is garbage collected.
For example the
shallow size of an instance of java.lang.String will not include the memory
needed for the underlying char[] where as retained size includes.

