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

后端 未结 6 1120
太阳男子
太阳男子 2020-12-01 06:02

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

相关标签:
6条回答
  • 2020-12-01 06:40

    This happens to me too and it drives me nuts. It could be that the memory (ram) available is fragmented. Although you have enough free memory, there is no contiguous 512MB blocks available, it's all fragmented into smaller blocks! This is why you only see it "sometimes".

    Some things worth trying:

    • check if you're low on memory, try to close other apps. This happens to me sometimes even if I still have a good 3GB free out of my 8GB! That 3GB can be fragmented in blocks which are all smaller than 512MB [ex: if you have -Xmx512m]... Rebooting is a way to defrag your memory. Or close firefox, that'll free up a gig ;-)

    • also, surprisingly, check your swap space [free disk space]! Depends of machine/JVM/etc implementation. But if you're low on swap space and your memory is fragmented, that could be another cause.

    • lower your -Xmx to maybe -Xms128m -Xmx512m to make it easier to find a contiguous block of free memory [128m]. This might not be a good idea if gradle truly needs 512m minimum. Given that we're talking about gradle, ignore this bullet point (could be a useful tip for other cases/worth noting).

    • double check your Xms/Xmx in ~/.gradle/gradle.properties attribute: org.gradle.jvmargs

    • use idea64.exe [64bit] and if you think IDEA is using the wrong JDK [32bit], in latest Intellij IDEA [14.1.3 as of this writting], go to "Settings"->"Build,Execution,Deployment" -> "Gradle": "use the default wrapper" and select the Gradle JVM you'd like (if you think it uses the wrong one, you'll see it here".

    • finally, this is just a guess but: in the previous bullet, I wonder if you select "use project JDK", if that makes it easier to find contiguous memory. I'm not sure if that means that Gradle will use intellij IDEA's already reserved memory block. So, instead of having two processes, you only have one and you could reserve a bigger memory block when IDEA starts up. But I'm not sure if that's accurate of if that's an option to suggest to Intellij...

    I agree with you, I've never had any memory issues with IDEA [well no issues AT ALL] until gradle integration came along.

    0 讨论(0)
  • 2020-12-01 06:44

    Installing 64 bit Java solved it for me

    0 讨论(0)
  • 2020-12-01 06:44

    In your android folder there is a gradel.properties file and add the following lines:

    org.gradle.jvmargs=-XX\:MaxHeapSize\=256m -Xmx256m
    

    I ran into this while using Intellij and Flutter. Also another property you may find useful to add is declaring where the JDK is.

    org.gradle.java.home=C:\\Your\\JDK\\path
    
    0 讨论(0)
  • 2020-12-01 06:51

    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!

    0 讨论(0)
  • 2020-12-01 06:52

    Although this question is a bit older I would like to come up with the (possible) rootcause of the problem: the JVM requests a whole block of memory on startup. If it couldn't find it, the "Could not reserve..." error occurs. John Pape wrote an enlighting article in IBM's devblog about this issue: https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/why_wont_my_jvm_start_with_this_heap_size?lang=en

    This is solving the problem for me:

    • variant a: using a 64 bit version of Java, so to give Java a bigger area of possible connected free memory
    • variant b: With 32 bit Java using smaller XMX amount. In the gradle.properties file I just use org.gradle.jvmargs=-Xmx150m and Gradle has no problems.
    0 讨论(0)
  • 2020-12-01 06:56

    In my case I had too much things opened. Freeing memory made it work.

    0 讨论(0)
提交回复
热议问题