DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Momento Migrates Object Cache as a Service to Ampere® Altra®
  • Why I Ditched Redis for Cloudflare Durable Objects in My Rate Limiter
  • Real-Object Detection at the Edge: AWS IoT Greengrass and YOLOv5
  • Monitoring and Managing the Growth of the MSDB System Database in SQL Server

Trending

  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • Introduction to Retrieval Augmented Generation (RAG)
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • AI Paradigm Shift: Analytics Without SQL
  1. DZone
  2. Coding
  3. Languages
  4. Shallow, Retained, and Deep Size

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.

By 
Grzegorz Mirek user avatar
Grzegorz Mirek
·
Sep. 02, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
17.4K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Object (computer science)

Published at DZone with permission of Grzegorz Mirek. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Momento Migrates Object Cache as a Service to Ampere® Altra®
  • Why I Ditched Redis for Cloudflare Durable Objects in My Rate Limiter
  • Real-Object Detection at the Edge: AWS IoT Greengrass and YOLOv5
  • Monitoring and Managing the Growth of the MSDB System Database in SQL Server

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook