Operations 6 min read

How to Diagnose Java OOM Crashes with Eclipse MAT: Step‑by‑Step Guide

When a production Java service repeatedly restarts and triggers full GC and OutOfMemoryError alerts, this guide shows how to capture heap dumps using JVM flags, install and configure Eclipse Memory Analyzer (MAT), and systematically analyze the dump to pinpoint memory leaks, high usage, and problematic code.

Thoughts on Knowledge and Action
Thoughts on Knowledge and Action
Thoughts on Knowledge and Action
How to Diagnose Java OOM Crashes with Eclipse MAT: Step‑by‑Step Guide

Problem Overview

A Java service in production repeatedly restarted, generating full GC alerts and OutOfMemoryError: Java heap space. The relevant log excerpt is:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: Java heap space] with root cause
java.lang.OutOfMemoryError: Java heap space

The JVM was started with options that force a heap dump on OOM:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path/to/dumpfile.hprof

Eclipse Memory Analyzer (MAT)

MAT is an offline tool for analyzing JVM heap dumps. It helps locate memory leaks, OOM conditions, and unusually high memory consumption.

Heap Dump File Structure

An .hprof file produced by Oracle‑based JVMs contains:

Class metadata

Object instance data

GC roots

Thread stacks and local variables

Installing MAT

Download the appropriate package from https://eclipse.dev/mat/download/ for your OS and JDK version. After extracting:

Verify the JDK version with java -XshowSettings:properties -version On macOS, edit Info.plist (inside /Applications/MemoryAnalyzer.app/Contents) to point to the JDK binary, e.g.:

<array>
  <string>-vm</string>
  <string>/Library/Java/JavaVirtualMachines/jdk-17.0.12.jdk/Contents/Home/bin</string>
  <string>-keyring</string>
  <string>~/.eclipse_keyring</string>
</array>

Increase MAT's own heap size by editing Eclipse/MemoryAnalyzer.ini and adding: -Xmx4096M If the platform metadata area cannot be written, launch MAT from the command line with an explicit data directory:

./MemoryAnalyzer -data ./dump

Analyzing the Dump

Open the .hprof file via “Open a Heap Dump”. MAT shows an overview of memory usage. Use the “Leak Suspects” link to generate a report that lists potential leaks.

Select a “Problem Suspect” entry to view the associated thread stack, which usually points to the offending code path.

Key MAT Views

Histogram : Shows the number of instances per class, with columns for shallow heap (object’s own memory) and retained heap (object plus everything it references).

Dominator Tree : Visualizes root objects and the total memory they dominate, helping identify large object graphs.

Thread Overview : Provides activity and stack information for each thread, useful for correlating leaks with execution paths.

By interpreting these views you can pinpoint the code responsible for excessive allocation and apply targeted optimizations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaPerformance debuggingMemory AnalyzerOutOfMemoryErrorHeap Dump
Thoughts on Knowledge and Action
Written by

Thoughts on Knowledge and Action

Travel together, with knowledge and action all the way

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.