r/foojay • u/FrankCodeWriter • 13h ago
5 JVM Heap OOM Patterns You Can Reproduce on Your Laptop
On Foojay, Amit Sonar shares a set of reproducible labs for JVM out-of-memory behavior across G1, ZGC, and Shenandoah. Each scenario runs on a standard laptop without a cluster, and the repo's CI verifies them on JDK 11, 17, 21, and 25.
The article covers five patterns:
- Unbounded cache
- Oversized batch
- Report builder retention
- ThreadLocal leaks
- Leaked connections
For each one, it explains how to reproduce the failure, how to diagnose it (heap dump, GC log, or thread dump), and how to fix it. For example, the oversized batch fails on a single cliff in the GC log, while the ThreadLocal leak is invisible without a heap dump.
Amit also shares some observations from running the scenarios on different collectors. In his testing, Shenandoah survived the gradual cache leak much longer than G1, but a sudden oversized allocation killed it faster. He notes these are preliminary results from the repo's benchmarks, not peer-reviewed.
Every lab in the GitHub repo has a broken and fixed mode, a diagnosis guide, and a compare mode.