Skip to main content

Posts

Showing posts from April, 2025

How to Capture and Analyze a Heap Dump

In this post, we'll dive into the practical aspects of capturing and analyzing Java heap dumps. This article continues from our previous deep dive, Java Dumps Uncovered: When to Use Thread Dump, Heap Dump, or Core Dump — where we explored the scenarios in which each type of dump is appropriate. Quick Summary Refer to the section on When to Take a Heap Dump from the previous post to understand the right circumstances for capturing heap dumps — such as frequent OutOfMemoryError s or excessive memory retention issues. Ways to Capture a Heap Dump There are several ways to generate a heap dump in Java. In this post, we'll demonstrate these using a sample Java application that consumes significant memory via ArrayList , HashMap , and other objects. You can find the sample code in this GitHub Gist . Before you can capture a heap dump, you'll need to identify the Java process ID (PID). You can do this using either of the following commands: $ jps or $ ps aux | grep java Once you ...