I have a Java program that is launched by a batch file with a line like this:
javaw -Xms64m -Xmx1024m com.acme.MyProgram
However, on some computers the program will not launch and displays the following message:
Could not reserve enough space for object heap. Could not create the Java virtual machine.
The problem seems to be the the maximum size of the memory allocation pool is larger than the computer can handle. Reducing the maximum size of the memory allocation pool from 1024m to 512m seems to resolve the problem.
Is there a way I can determine how much memory is available on the computer ahead of time (from within the batch file) and determine whether to use -Xmx1024m
or -Xmx512m
in the batch file invocation? Note that this batch file only needs to work on Windows.