Summary
When building or running a Spring project from IntelliJ IDEA, the IDE may fail with the error:
java.lang.OutOfMemoryError: insufficient memory
This error has two common causes: insufficient heap allocated to IntelliJ IDEA's shared build process, or a 32-bit JDK configured as the project SDK. Check both, starting with the heap size.
Symptoms
- Build or run fails immediately or during compilation
- Error appears in the Build output or Run console
- The compiler error may be prefixed with
java:(for example,java: OutOfMemoryError: insufficient memory) - The error message may alternate between
Java heap spaceandinsufficient memoryas the configured heap value changes - Project worked previously without issues
- Updating IntelliJ IDEA does not resolve the problem
Root Cause
IntelliJ IDEA uses a separate JVM (shared build process) to compile and build projects. This process has its own heap size limit, which is independent of:
- The IDE heap size
- The application (Spring Boot) runtime heap size
There are two independent reasons this JVM can fail with an out-of-memory error:
1. The shared build process heap is too small. Over time, memory requirements can increase due to project growth, additional modules or dependencies, annotation processing (e.g., Lombok, MapStruct), or JDK/IDE updates that change compiler behavior. A previously sufficient value (e.g., 700 MB) may no longer be adequate.
2. The project SDK is a 32-bit JDK. When the project SDK differs from the IDE's runtime, the Java compiler runs as a separate forked process using the project's JDK. A 32-bit JVM on Windows can address only about 1.3–1.5 GB of heap regardless of the configured -Xmx. In this case, increasing any heap setting does not help, because the compiler cannot use more than the 32-bit limit. Requesting a heap larger than a 32-bit process can reserve changes the error from Java heap space to insufficient memory. A 32-bit JDK is installed under C:\Program Files (x86)\, while a 64-bit JDK is installed under C:\Program Files\.
Resolution
Step 1: Increase the shared build process heap size
-
Open File → Settings (or
Ctrl + Alt + S) -
Navigate to Build, Execution, Deployment → Compiler
-
Increase Shared build process heap size
- Example: change from 700 MB to 1400 MB (a value of 2048–4096 MB is sufficient for most projects)
-
Click Apply and OK
-
Restart IntelliJ IDEA
Step 2: Verify the project SDK is a 64-bit JDK
If increasing the heap has no effect, check whether the project SDK is a 32-bit JDK.
- Open File → Project Structure → Project
- Inspect the configured SDK path. A path under
C:\Program Files (x86)\indicates a 32-bit JDK. - Select a 64-bit JDK. If none is installed, use Add SDK → Download JDK in the same dialog. The same Java version is fine; only the 64-bit build is required.
- Rebuild the project.
A 64-bit JDK can use a large heap, so the build process and forked compiler are no longer limited to ~1.3–1.5 GB.
Comments
0 comments
Please sign in to leave a comment.