为什么java -Xmx不能正常工作?

可能重复:
Linux在VPS上的内存不足

在我的Ubuntu 11.10 VPS中,在运行jar文件之前:

# free -m total used free shared buffers cached Mem: 256 5 250 0 0 0 -/+ buffers/cache: 5 250 Swap: 0 0 0 

运行限制为最大32M内存的jar文件:

 java -Xms8m -Xmx32m -jar ./my.jar 

现在的内存状态如下:

 # free -m total used free shared buffers cached Mem: 256 155 100 0 0 0 -/+ buffers/cache: 155 100 Swap: 0 0 0 

这个jar子占用了150M的内存。

我不能运行任何其他的Java命令:

 # 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. 

我想知道为什么-Xmx参数不起作用?

如何限制使用内存的jar文件?

-Xmx参数定义堆大小,也就是您可以在程序中分配的内存。 java二进制文件和加载的jar文件都需要额外的空间。

不是Java用完所有的内存,系统也会消耗RAM来caching数据(查看free -mtop的caching输出)

您正在运行Java(BLOATED软件)的256MB RAM VPS 没有交换 。 你真的确定要走这条路吗?