java memory_error ai_generated true

java.lang.OutOfMemoryError: GC overhead limit exceeded

ID: java/gc-overhead-limit

Also available as: JSON · Markdown
80%Fix Rate
87%Confidence
100Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
17 active

Root Cause

The JVM is spending more than 98% of its time doing garbage collection and recovering less than 2% of the heap. This usually indicates a memory leak or that the application requires more memory than allocated.

generic

Workarounds

  1. 88% success Profile the heap with a heap dump and identify the objects consuming the most memory
    1. Add -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof to JVM args. 2. Reproduce the error and analyze the heap dump with Eclipse MAT or VisualVM. 3. Look for the dominator tree — the largest retained objects. 4. Check for common leaks: unbounded caches, static collections that grow indefinitely, listeners not being deregistered, session objects not being cleaned up. 5. Fix the leak and retest.
  2. 82% success Switch to a more efficient GC algorithm and right-size the heap after profiling
    1. Profile first to confirm the application is not leaking. 2. If memory usage is legitimately high, increase -Xmx to give more headroom. 3. Consider switching to G1GC (-XX:+UseG1GC) or ZGC (-XX:+UseZGC) which handle large heaps more efficiently. 4. Monitor with -Xlog:gc* to verify GC overhead drops to acceptable levels.

Dead Ends

Common approaches that don't work:

  1. Disabling the GC overhead limit check with -XX:-UseGCOverheadLimit 90% fail

    This just converts the GC overhead error into a regular OutOfMemoryError: Java heap space. The application will still run out of memory, but now without the early warning. Performance will be terrible as the JVM spends nearly all time in GC.

  2. Increasing heap size without profiling to find the memory issue 60% fail

    If there is a memory leak, increasing heap size only delays the inevitable. The application will eventually exhaust the larger heap too. Meanwhile, GC pauses become longer with a bigger heap, degrading performance.

Error Chain

Leads to:
Preceded by:
Frequently confused with: