3 Leading Causes of JVM OutOfMemoryError

The most frequent causes of OutOfMemoryError (OOM) revealed by heap dumps are memory leaks from unreferenced objects, excessive object creation, and misconfigured caches holding too much data.

The top 3

  1. 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`).
  2. Metaspace OOM: Top 3 Causes & Fixes: The `java.lang.OutOfMemoryError: Metaspace` error, which replaced `PermGen space` in Java 8, is primarily caused by classloader leaks from hot deployments, excessive dynamic class generation via reflection or scripting, or an insufficient maximum Metaspace size configured with `-XX:MaxMetaspaceSize`.
  3. GC Overhead Limit: Top 3 Prevention Strategies: The `java.lang.OutOfMemoryError: GC overhead limit exceeded` occurs when the JVM spends over 98% of its time on garbage collection but reclaims less than 2% of the heap. To prevent this, increase the JVM heap size (`-Xmx`), optimize code to reduce object creation and eliminate memory leaks, or switch to a more efficient garbage collector like G1GC.

Sources

Open the full topic