Could not reserve enough space for object heap

后端 未结 26 1341
余生分开走
余生分开走 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:33

    I recently faced this issue. I have 3 java applications that start with 1024m or 1280m heap size. Java is looking at the available space in swap, and if there is not enough memory available, the jvm exits.

    To resolve the issue, I had to end several programs that had a large amount of virtual memory allocated.

    I was running on x86-64 linux with a 64-bit jvm.

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

    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 Variable name: Path
      Variable value: %PATH%;C:\Program Files\Java\jre6\bin;F:\JDK\bin;

    Change this to your appropriate path.

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

    If you're running 32bit JVM, change heap size to smaller would probabaly help. You can do this by passing args to java directly or through enviroment variables like following,

    java -Xms128M -Xmx512M
    JAVA_OPTS="-Xms128M -Xmx512M"
    

    For 64bit JVM, bigger heap size like -Xms512M -Xmx1536M should work.

    Run java -version or java -d32, java--d64 for Java7 to check which version you're running.

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

    In case you are running a java program: - run your program in a terminal using the correct command for linux it would be 'java -jar myprogram.jar' and add -Xms256m -Xmx512m, for instance: 'java -jar myprogram.jar Xms256m -Xmx512m'

    In case you are running a .sh script (linux, mac?) or a .bat script (windows) open the script and look for the java options if they are present and increase the memory.

    If all of the above doesn't work, check your processes (ctrl+alt+delete on windows) (ps aux on linux/mac) and kill the processes which use allot of memory and are not necessary for your operating system! => Try to re-run your program.

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

    I ran into this when using javac, and it doesn't seem to pick up on the command line options,

    -bash-3.2$ javac -Xmx256M HelloWorldApp.java 
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    

    so the solution here it so set _JAVA_OPTIONS

    -bash-3.2$ export _JAVA_OPTIONS="-Xmx256M"
    -bash-3.2$ javac HelloWorldApp.java 
    Picked up _JAVA_OPTIONS: -Xmx256M
    

    And this compiles fine.

    This happens to me on machines with a lot of RAM, but with lower memory ulimits. Java decides to allocate a big heap because it detects the ram in the machine, but it's not allowed to allocate it because of ulimits.

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

    32-bit Java requires contiguous free space in memory to run. If you specify a large heap size, there may not be so much contiguous free space in memory even if you have much more free space available than necessary.

    Installing a 64-bit version of Java helps in these cases, the contiguous memory requirements only applies to 32-bit Java.

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