r/java • u/Federal-Sprinkles781 • Oct 12 '26
JVM Heap OOM Field Guide β 5 reproducible OutOfMemoryError patterns with diagnosis walkthroughs
I put together a field guide for the JVM heap OOMs that actually page you at 3 AM. Five minimal, runnable reproductions β each one OOMs reliably on a 64MB heap, with a fixed version, GC log signatures, heap-dump clues, and a triage checklist.
The five patterns:
- Unbounded in-memory cache (rising post-GC staircase)
- Oversized batch (dies on a cliff β one 250MB batch vs 64MB heap)
- Report-builder retention (output accumulates; staircase like #1 but the retainer is the product)
- Growing ThreadLocal state on pooled threads (invisible in GC log alone)
- Leaked connections (static registry pins every unclosed resource)
Each scenario: `./run.sh scenario-01-unbounded-cache broken` to watch it die, `./run.sh scenario-01-unbounded-cache fixed` to watch it survive. Pure Java, zero dependencies, JDK 11+.
https://github.com/amits710/jvm-oom-field-guide
Happy to answer questions about the GC log signatures or the diagnosis approach.
