Java heap dump analyzer

Drop an .hprof heap dump and see where the memory goes: a class histogram, the biggest objects, duplicate strings, and every thread's stack at the moment of the dump. It reads the file in your browser, in pieces, so a dump of several gigabytes works and never leaves your device. Heap dumps hold everything the program had in memory, passwords and customer data included: don't upload them anywhere you wouldn't paste them.

Drop a heap dump here, or

Or open a sample: (20 MB, from a small program with 20,000 orders in a cache)

How to take a heap dump

jcmd <pid> GC.heap_dump /tmp/heap.hprof
Runs a full GC first and dumps only live objects (add -all to keep the garbage).
jmap -dump:live,format=b,file=heap.hprof <pid>
The older tool; the same file.
-XX:+HeapDumpOnOutOfMemoryError
Start the JVM with this (and -XX:HeapDumpPath=…) and it writes a dump the moment it runs out of memory: the most useful dump there is, because it shows what filled the heap.

A dump is about the size of the used heap, and writing it pauses the application. Compress it before moving it: dumps shrink a lot.

Reading the histogram

Shallow size is an object's own bytes: its header and fields, with references counted as pointers, not what they point to. A HashMap is small; its table and entries are separate rows. So the top of the histogram is nearly always byte[] (the characters of every String, and buffers), Object[] (the insides of collections) and String. Look further down for the application's own classes: an unexpectedly large count there, such as 20,000 orders that should have been released, is usually the leak.

Finding what keeps those objects alive needs the whole object graph (retained sizes and dominator trees). For that, open the dump in Eclipse MAT or VisualVM; this page tells you which classes to look at.

The format

HPROF is a header (JAVA PROFILE 1.0.2, the size of an object ID, a timestamp) and then a sequence of records, each with a tag, a time and a length. Names come first as UTF8 records, then LOAD CLASS, stack frames and traces, and then HEAP DUMP SEGMENTs, which contain the GC roots, a CLASS DUMP for each class, and an INSTANCE, OBJECT ARRAY or PRIMITIVE ARRAY DUMP for every object. The Records tab shows how a dump splits into these.