Java Heap Dump & Class Histogram Analyzer

When a JVM throws OutOfMemoryError or its heap keeps growing, the question is always “what is holding all that memory?”. Paste a class histogram or load a heap dump to get the answer sorted by bytes.

Histogram vs. full heap dump

jmap -histo:live <pid> prints a class histogram: for every loaded class, how many instances exist and how many bytes they occupy. It is quick, small (a few hundred KB) and safe to run in production, and it answers 80% of memory questions. A full heap dump (jmap -dump:live,format=b,file=heap.hprof <pid> or -XX:+HeapDumpOnOutOfMemoryError) captures every object and reference. It is large — often as big as the heap — but lets you trace who is holding the leaking objects.

What to look for

Sort by bytes. byte[], char[] and String are always near the top; that is normal. Suspicious signs are an application class with millions of instances, a collection class (HashMap$Node, ArrayList, LinkedList$Node) with far more entries than your data model suggests, or framework objects — Hibernate sessions, Netty buffers, cache entries — that should be short-lived but accumulate. Compare two histograms taken minutes apart: the class whose count grows monotonically is your leak.

Common causes of Java memory leaks

Static collections that are only ever added to; caches without size or time bounds; listeners and callbacks registered but never removed; ThreadLocal values in pooled threads; unclosed streams, statements or HTTP clients; and classloader leaks on redeploy in application servers. The histogram usually points at the symptom (the growing class); the full dump's dominator tree points at the cause (the collection or static field retaining it).

How to use it

  1. Run jmap -histo:live <pid> and paste the output, or upload an .hprof file in the upload tab.
  2. Review classes sorted by retained bytes and instance count; filter by package to focus on your own code.
  3. Take a second histogram later and compare counts to identify growth.

Reading a histogram

The top of a typical jmap -histo output:

 num     #instances         #bytes  class name
----------------------------------------------
   1:       2891213      486203816  [B
   2:       2654012       84928384  java.lang.String
   3:        981422       47108256  java.util.HashMap$Node
   4:        412093       32967440  com.example.order.OrderLine
   5:         32011       28809900  [Ljava.util.HashMap$Node;

400 000 OrderLine objects at 32 MB might be fine for a batch job and alarming for a stateless API. The tool parses the table, converts bytes to MB and lets you sort and filter.

Common use cases

Frequently asked questions

Is my heap dump uploaded to your servers?

Histogram text is parsed in your browser. .hprof files require a backend because they can be gigabytes; upload only works if you configure a backend URL (self-hosted or provided separately). Nothing is sent otherwise.

What is the difference between -histo and -histo:live?

The :live option forces a full GC first so only reachable objects are counted. Use it when hunting leaks; omit it if you also want to see garbage awaiting collection.

Why are byte[] and String always at the top?

Nearly everything — text, buffers, serialized payloads — is ultimately stored in byte or char arrays. Look at which application classes reference them rather than at the arrays themselves.

Can I use this instead of Eclipse MAT or VisualVM?

For histograms, yes — it is faster. For deep retained-size and dominator-tree analysis of a multi-GB dump, a desktop tool like Eclipse MAT remains the right choice.

Related tools

Explore all developer tools →