Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy-to-use performance and memory .NET profiler for Windows, Linux and macOS.
Secure and easy profiling in cloud, containers and clustered environments.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

Group objects by shallow size

Analyzing a memory snapshot can be a daunting task, especially when you're dealing with a large Java application that's potentially leaking memory or using it inefficiently. One useful approach to simplify this analysis is by grouping objects by their shallow size.

Shallow size is the amount of allocated memory that is used to store the object itself, not taking into account any referenced objects. For example, an array object will have a shallow size that includes only the memory used for the array header and the references it contains, not the objects that those references point to.

YourKit Java Profiler allows you to evaluate how many small, medium and large objects are in the heap, and how much memory they use:

Grouping objects by shallow size

How grouping by shallow size can be used

1. Simplifies analysis: Grouping by shallow size lets you quickly identify types of objects that, individually, take up a lot of space.

2. Identify high memory consumers: Large objects by shallow size are the first suspects when analyzing memory usage. They can either be necessary or signs of memory leaks or inefficiencies.

2. Initial filter: Before delving into deep size analysis (which includes the object and all its dependencies), a shallow size analysis can serve as a first step in pinpointing problem areas.

Best practices

Prioritize by frequency and size

When sorting objects by shallow size, take note of both the individual size and the frequency of objects. Sometimes a large number of small objects can be just as problematic as a small number of large objects.

Focus on your own classes

Standard library classes are generally well-optimized. Your efforts are better spent focusing on classes that you or your team have written.

Review lifecycle

Consider the lifecycle of large objects. Are they being held in memory for longer than needed? Sometimes the issue isn't just size but longevity.

Use multiple metrics

Don't solely rely on shallow size; also consider other metrics like retained size and the number of instances. A full understanding comes from analyzing multiple dimensions.

YourKit uses cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the Privacy Policy.