Could not reserve enough space for object heap

后端 未结 26 1342
余生分开走
余生分开走 2020-11-22 05:59

I am getting the following exception repeatedly each time I try to run the program.

Error occurred during initialization of VM

Could not reserve e

相关标签:
26条回答
  • 2020-11-22 06:39

    Suppose your class is called Test in package mypackage. Run your code like this:

    java -Xmx1024m mypackage.Test
    

    This will reserve 1024 MB of heap space for your code. If you want 512 MB, you can use:

    java -Xmx512m mypackage.Test
    

    Use little m in 1024m, 512m, etc

    0 讨论(0)
  • 2020-11-22 06:42

    Anyway, here is how to fix it: Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System Variables->New: Variable name: _JAVA_OPTIONS Variable value: -Xmx512M

    OR

    Change the ant call as shown as below.

       <exec
            **<arg value="-J-Xmx512m" />**
        </exec>
    

    It worked for me.

    0 讨论(0)
  • 2020-11-22 06:46

    Combined with -Xmx512M use -d64 to make sure you're running 64-bit VM. On a 64-bit machine I thought for sure I was running 64-bit virtual machine, but no. After installing 64-bit Java the -d64 option works and -Xmx allows much larger memory sizes.

    java -d64 -Xmx512M mypackage.Test
    
    0 讨论(0)
  • 2020-11-22 06:47

    Open gradle.properties file in android folder.

    Replace this line:

    org.gradle.jvmargs=-Xmx1536M
    

    with:

    org.gradle.jvmargs=-Xmx512m
    

    Explanation: Max limit from Gradle document:

    If the requested build environment does not specify a maximum heap size, the Daemon will use up to 512MB of heap.

    0 讨论(0)
  • 2020-11-22 06:48

    Sometimes, this error indicates that physical memory and swap on the server actually are fully utilized!

    I was seeing this problem recently on a server running RedHat Enterprise Linux 5.7 with 48 GB of RAM. I found that even just running

    java -version
    

    caused the same error, which established that the problem was not specific to my application.

    Running

    cat /proc/meminfo
    

    reported that MemFree and SwapFree were both well under 1% of the MemTotal and SwapTotal values, respectively:

    MemTotal:     49300620 kB
    MemFree:        146376 kB
    ...
    SwapTotal:     4192956 kB
    SwapFree:         1364 kB
    

    Stopping a few other running applications on the machine brought the free memory figures up somewhat:

    MemTotal:     49300620 kB
    MemFree:       2908664 kB
    ...
    SwapTotal:     4192956 kB
    SwapFree:      1016052 kB
    

    At this point, a new instance of Java would start up okay, and I was able to run my application.

    (Obviously, for me, this was just a temporary solution; I still have an outstanding task to do a more thorough examination of the processes running on that machine to see if there's something that can be done to reduce the nominal memory utilization levels, without having to resort to stopping applications.)

    0 讨论(0)
  • 2020-11-22 06:49

    I got the same error and it got resolved when I deleted temp files using %temp% and restarting eclipse.

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