Could not reserve enough space for object heap

后端 未结 26 1304
余生分开走
余生分开走 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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.

提交回复
热议问题