OutOfMemoryError Java Origin: Application & API Last updated 13 Oct 2026

java.lang.OutOfMemoryError: Java heap space

The JVM ran out of heap memory and garbage collection couldn’t free enough.

Exact message you may see Java heap spaceGC overhead limit exceeded
Seen on: Java Android

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

  1. Increase heap: -Xmx2g (or -XX:MaxRAMPercentage=75 in containers)
  2. Capture a heap dump: -XX:+HeapDumpOnOutOfMemoryError and analyze with Eclipse MAT
  3. Stream large data instead of loading it

Detailed fix by platform

Java

  1. In Docker/Kubernetes use -XX:MaxRAMPercentage so the heap respects the container limit.

Android

  1. Gradle builds: set org.gradle.jvmargs=-Xmx4g in gradle.properties.

How to diagnose

  1. Variant — Heap, Metaspace, GC overhead or native threads?
  2. Trend — Does memory grow steadily (leak) or spike (load)?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0xC0000005 — The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation (Windows)0xC0000005Allowed memory size exhausted — PHP Fatal error: Allowed memory size of X bytes exhausted (PHP)Allowed memory size e…Cannot allocate memory — fork: Cannot allocate memory / ENOMEM (Linux)Cannot allocate memoryConcurrentModificationException — java.util.ConcurrentModificationException (Java)ConcurrentModificatio…double free or corruption — C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped) (C/C++)double free or corrup…EXC_BAD_ACCESS — Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) (iOS)EXC_BAD_ACCESSGradle Java heap space — Gradle: Expiring Daemon because JVM heap space is exhausted / java.lang.OutOfMemoryError: Java heap space during build (Android)Gradle Java heap spaceheap out of memory — FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (Node.js)heap out of memoryOutOfMemo…

Explore the map of this error Full error map →

🧠 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.