Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Shallow, Retained, and Deep Size

DZone's Guide to

Shallow, Retained, and Deep Size

In this article, we look at the three different sizes that objects can be in a heap analysis, and what this means for your performance.

· Performance Zone ·
Free Resource

Maintain Application Performance with real-time monitoring and instrumentation for any application. Learn More!

If you ever worked with heap analysis, you might have encountered terms such as shallow, retained, and deep size of an object. It doesn’t really matter if we’re talking about analyzing a JVM heap dump with VisualVM or a JavaScript heap snapshot with Chrome DevTools – the terms are the same. The difference between shallow, retained, and deep size is rather straightforward and it can be easily depicted with the following images:

Image title

Shallow size – size of the object itself including only references to other objects, without objects which are referenced.


Image title

Retained size – size of the object including references to other objects and objects which are referenced, but are not shared with any other objects. In other words, the retained memory of an object is the amount of memory that would be freed if the object A was eligible to be collected by GC. Memory of the object E couldn’t be freed because it is also an instance variable of object B. 

Image title

Deep size – size of the object including references to other objects and objects which are referenced, even if they are shared with other objects.

Collect, analyze, and visualize performance data from mobile to mainframe with AutoPilot APM. Learn More!

Topics:
performance ,memory management ,heap dump ,heap

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}