Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Gradle error "Could not reserve enough space for object heap" constantly in Intellij IDEA

So I have a problem with memory allocation. Sometimes it works, and sometimes it doesn't. I've read this thread and tried the advice there multiple times. Sometimes -Xms512m -Xmx768m works, sometimes -Xms256m -Xmx512m. I'm sick and tired of having to tweak this setting in IntelliJ under the Build, Execution, Deployment > Build Tools > Gradle > Gradle VM options setting. Is there no setting that solves this once and for all?

I have 16GB of RAM on my Windows 7 computer, I'm running IntelliJ IDEA EAP 14 build 138.2210.3, 64 bit version. Android Gradle build plugin v0.12.

I'm suspecting gradle is not running in 64 bit mode, or else it would have ~7 GB of free memory to eat from. Why is it not utilizing this?

EDIT:

I got the same error in Visual Studio 2015 with cordova 5.1.1 under Windows 10. See my solution below.

like image 867
Nilzor Avatar asked Oct 01 '14 14:10

Nilzor


People also ask

Could not reserve enough space for 2097152KB object heap Error occurred during initialization of VM?

You might get an specific error Could not reserve enough space for 2097152kb object heap in case you are using any tool. It simply means that JVM is not able to acquire 2 GB heap space which is required by the tool by default.

How do you reserve enough space for an object heap?

To fix the error "Could not reserve enough space for object heap", add the options "-Xmx<size>m" to set the maximum size for the object heap memory allocation. This must be set large enough to accommodate loading your application into memory, but smaller than your requested total memory allocation by 2GB.

Could not reserve enough space for JVM?

“Could not reserve enough space for object heap” is a specific JVM error that is raised when Java process cannot create the virtual machine due to memory constraints encountered on the running system: java -Xms4G -Xmx4G -jar HelloWorld.

Could not reserve enough space for 2097152KB object heap error?

To fix the could not reserve enough space for 2097152KB object heap error message, just change the -Xmx setting to something more conservative such as 512m or 1024m.


2 Answers

I got the same error in Visual Studio 2015 with cordova 5.1.1 under Windows 10.

To solve the issue, set this environment variable:

_JAVA_OPTIONS=-Xmx512M 
  1. Right click on start-button and open "System"
  2. Search for "Advanced system settings" and open it
  3. Click the button "Environment Variables ..."
  4. In System Variables, click "New..."
  5. New Variable Name: _JAVA_OPTIONS
  6. New Variable Value: -Xmx512M
  7. Click OK
  8. Restart Visual Studio, so the variable is picked up

This Article point me in the right direction. I did change the instructions a littel bit, so they fits to Windows 10.

Hope it helps someone!

like image 70
Bjoerg Avatar answered Oct 04 '22 15:10

Bjoerg


Installing 64 bit Java solved it for me

like image 28
Nilzor Avatar answered Oct 04 '22 17:10

Nilzor