使用-Xmx3G“初始化 VM 时发生错误; 无法为对象堆保留足够的空间”

首先,我有一个8GB 内存的盒子,所以我怀疑总内存是个问题。 此应用程序在6gb 或更少的机器上运行良好。

我试图在 Eclipse 的 Run Configuration 中的“ VM Arguments”下使用-Xmx3G 保留3 GB 的空间。

每次我试图保留超过1500mb 的内存时,都会出现这样的错误: 使用-Xmx3G“初始化 VM 时发生错误; 无法为对象堆保留足够的空间”

这是怎么回事?

672942 次浏览

Could it be that you're using a 32-bit jvm on that machine?

This is actually not an Eclipse-specific issue; it's a general Java-on-Windows issue. It's because of how the JVM allocates memory on Windows; it insists on allocating a contiguous chunk of memory, which often Windows can't provide, even if there are enough separate chunks to satisfy the allocation request. There are utilities that will try to help Windows "defrag" its memory, which would, in theory, help this situation; but I've not really tried them in earnest so can't speak to their effectiveness. One thing that I've heard sometimes that might help is to reboot Windows and, before starting any other apps, launch the Java app that needs the big chunk of memory. If you're lucky, Windows won't have fragmented its memory space yet and Java will get the contiguous block that is asks for.

Somewhere out on the interwebs there are more technical explanations and analyses of this issue, but I don't have any references handy.

I did find this, though, which looks helpful: https://stackoverflow.com/a/497757/639520

Make sure that Eclipse is actually running the same JVM you think it's running. If you use java in your web browser ever, you likely have a 32-bit version floating around too that might be taking precedence if it installed or updated lately.

To be absolutely sure, I recommend adding these two lines to your eclipse.ini file at the top:

-vm
C:/Java/jdk1.6.0_27/bin

...where on my machine C:/Java/jdk1.6.0_27/bin where the JVM I know is 64-bit is located. Be sure to have the bin folder there.

(As a bonus, on Windows 7, this also allows you to actually "pin the tab" which is why I had to do this for my own usage)

First the JRE of 32bits can't use more ~1.5Gb of ram. So if you want more, use a 64bits JRE.

Second, When a new JVM starts, this sum the -Xmx property of the all JVM that are running, and check if there is enough memory left on the system to run at their own -Xmx, if is not enough then the error occurs.

This is the issue of Heap size. Edit your .bat (Batch file). It might be showing Heap size 1024. Change it to 512 Then it should work.

I was using Liferay with Tomcat server from eclipse IDE. I was stuck with this same error on click on server start up. Double click on server from eclipse. it open up Server Overview page. Updated memory arguments from -Xmx1024m -XX:MaxPermSize=256m to -Xmx512m -XX:MaxPermSize=256m. Then it was working for me.

I also had the same problem while using Eclipse which was 32 bit and the JVM used by it was 64 bit. When I routed the Eclipse to 32 bit JVM then it worked

Probably you are trying wrong options anyways. I got a similar error with supporting error log:

Java HotSpot(TM) Client VM warning: ignoring option PermSize=32M; support was removed in 8.0
Java HotSpot(TM) Client VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0

Im my case, the software did not support java 8 yet(script was using old JVM arguments) but I had had java 8 by default.

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: ;C:\Program Files\Java\jre6\bin;F:\JDK\bin;

Change this to your appropriate path.

One of the reason for this issue is no memory available for Tomcat to start. Try to delete the unwanted running software from windows and restart the eclipse and tomcat.

Just put # symbol in front of org.gradle.jvmargs=-Xmx1536m in gradle.properties

 # org.gradle.jvmargs=-Xmx1536m

I know that i am a bit late, but here my answer comes:

I just installed the Java online Version from Oracle(not the offline 64-Bit one).

After having added the JAVA_HOME ENV variable, it just worked!

Hope I could help :)

Solution is simple. No need to go deep into this issue.

If you are running on 64bit machine then follow below steps:

  • Unistall 32 bit java first (check in C:\Program Files (x86) for its existence)
  • Install the newer version JDK kit 64 bit (includes JRE)
  • Set the environment path (To avoid conflict error if you have two different 64bit JRE)
  • Check in command prompt by typing javac command.
  • Restart / Done

You can have two different Java installed but don't forgot to set path.

Please set JAVA_OPTS=-Xms256m -Xmx512m in environment variables, it should solve the issue, it worked for me.

Find out if you are using a 32bit version or 64bit version of Java. To know that use the command

java -version

The 3rd line of the output should give you if it 32bit or 64bit.

enter image description here

If it is 32bit uninstall and install a 64bit version.