java.lang.OutOfMemoryError: Java heap space
The JVM ran out of heap memory and garbage collection couldn’t free enough.
Java heap spaceGC overhead limit exceeded Meaning
Either the heap (-Xmx) is too small for the workload, or the application leaks memory (objects stay referenced). Variants: “GC overhead limit exceeded”, “Metaspace”, “unable to create native thread”.
Common causes
- Heap too small for the workload
- Memory leak (static collections, caches without eviction, listeners)
- Loading huge files/result sets into memory
- Container memory limit lower than JVM assumes
⚡ Quick fix
- Increase heap:
-Xmx2g(or-XX:MaxRAMPercentage=75in containers) - Capture a heap dump:
-XX:+HeapDumpOnOutOfMemoryErrorand analyze with Eclipse MAT - Stream large data instead of loading it
Detailed fix by platform
Java
- In Docker/Kubernetes use
-XX:MaxRAMPercentageso the heap respects the container limit.
Android
- Gradle builds: set
org.gradle.jvmargs=-Xmx4gin gradle.properties.
How to diagnose
- Variant — Heap, Metaspace, GC overhead or native threads?
- Trend — Does memory grow steadily (leak) or spike (load)?
- Heap dump — Which objects dominate?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Java
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026