简体   繁体   English

Java:尽管有足够的内存,但“无法为对象堆保留足够的空间”错误

[英]Java: "Could not reserve enough space for object heap" error, despite enough memory

When running a command like:运行以下命令时:

$ javac -J-Xmx1072M ...

everything works fine.一切正常。

When running the same command with larger memory:使用更大的内存运行相同的命令时:

$ javac -J-Xmx2048M ...

I get the following error:我收到以下错误:

Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.

However, I do not understand why, because when I run systeminfo in my windows command prompt, I get this info:但是,我不明白为什么,因为当我在 Windows 命令提示符下运行systeminfo时,我得到以下信息:

Total Physical Memory:     16,315 MB
Available Physical Memory: 6,351 MB
Virtual Memory: Max Size:  32,187 MB
Virtual Memory: Available: 13,666 MB
Virtual Memory: In Use:    18,521 MB

Meaning, I have plenty of physical memory left over.意思是,我还有很多物理内存。

What seems to be the issue?似乎是什么问题?

The JVM can't just pick any old memory anywhere for its object heap, it has to be contiguous ; JVM 不能为它的对象堆在任何地方挑选任何旧内存,它必须是连续的 meaning a continuous, unfragmented block of free memory.意味着一个连续的、未碎片化的空闲内存块。 While you theoretically might have enough raw memory free to launch a JVM with this heap size, if it's not contiguous then it's useless as far as the JVM is concerned.虽然理论上您可能有足够的可用原始内存来启动具有此堆大小的 JVM,但如果它不是连续的,那么就 JVM 而言它是无用的。

Note that this is far, far more likely to happen with a 32 bit address space (if you're using a 32 bit OS or 32 bit JVM), but can of course still happen regardless.请注意,使用 32 位地址空间(如果您使用的是 32 位操作系统或 32 位 JVM)时,这种情况发生的可能性要大得多,但无论如何仍然可能发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM