Top 3 Culprits of Java Heap OOM

The `java.lang.OutOfMemoryError: Java heap space` is often caused by memory leaks from unintentionally retained object references, applications handling excessively large data structures like huge collections or caches, or an improperly configured JVM with an insufficient heap size (`-Xmx`).

The top 3

  1. Top 3 Java Memory Leak Patterns: Static collections holding references, unclosed resources (like streams/connections), and forgotten listeners/callbacks are prime examples of objects unintentionally retained, preventing garbage collection.
  2. Heaviest Java Object Types in Heap OOM: Large arrays (e.g., `byte[]`), extensive `HashMap` or `ArrayList` usage, and the memory overhead of wrapper objects for primitives frequently exhaust heap space.
  3. Critical JVM Heap Sizing Misconfigurations: Common errors include under-allocating maximum heap size (`-Xmx`), not setting minimum (`-Xms`) and maximum heap sizes to equal values for stable performance, and failing to consider container memory limits.

Sources

Open the full topic