Possible Duplicate:
Linux out of memory on VPS
In my Ubuntu 11.10 VPS, Before I run the jar file:
# free -m
total used free shared buffers cached
Mem: 256 5 250 0 0 0
-/+ buffers/cache: 5 250
Swap: 0 0 0
Run a jar file that limited to maximum of 32M memory:
java -Xms8m -Xmx32m -jar ./my.jar
Now the memory state as follows:
# free -m
total used free shared buffers cached
Mem: 256 155 100 0 0 0
-/+ buffers/cache: 155 100
Swap: 0 0 0
This jar occupied 150M memory.
And I can't run any other java command:
# java -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
# java -Xmx8m -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
I want to know why the -Xmx parameter does not take effect?
How can I limit the jar file using the memory?
The
-Xmx
parameter defines the heap size, aka the memory you can allocate in the program. Thejava
binary and the loadedjar
file each needs additional space, naturally.It's not Java who used up all the memory, the system also consumes RAM to cache data (look at the cache output from
free -m
andtop
)You're running Java (BLOATED software) on a 256MB RAM VPS without swap. Are you really really sure you want to go down this path?