简体   繁体   English

无法为 object 堆保留足够的空间

[英]Could not reserve enough space for object heap

I am getting the following exception repeatedly each time I try to run the program.每次尝试运行该程序时,我都会反复收到以下异常。

Error occurred during initialization of VM虚拟机初始化时出错

Could not reserve enough space for object heap无法为 object 堆保留足够的空间

Could not create the Java virtual machine.无法创建 Java 虚拟机。

I tried to increase my virtual memory (page size) and RAM size, but to no avail.我试图增加我的虚拟 memory(页面大小)和 RAM 大小,但无济于事。

How can I eliminate this error?我怎样才能消除这个错误?

使用-XX:MaxHeapSize=512m (或您需要的任何大数字)(或简称-Xmx512m )运行 JVM

This can also be caused by setting something too large on a 32-bit HotSpot vm, for example:这也可能是由于在 32 位 HotSpot 虚拟机上设置太大而导致的,例如:

-Xms1536m -Xmx1536m

where this might/would work:可能/会起作用的地方:

-Xms1336m -Xmx1336m

I ran into this when using javac, and it doesn't seem to pick up on the command line options,我在使用 javac 时遇到了这个问题,它似乎没有在命令行选项上找到,

-bash-3.2$ javac -Xmx256M HelloWorldApp.java 
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

so the solution here it so set _JAVA_OPTIONS所以这里的解决方案是这样设置_JAVA_OPTIONS

-bash-3.2$ export _JAVA_OPTIONS="-Xmx256M"
-bash-3.2$ javac HelloWorldApp.java 
Picked up _JAVA_OPTIONS: -Xmx256M

And this compiles fine.这编译得很好。

This happens to me on machines with a lot of RAM, but with lower memory ulimits.这发生在我有大量 RAM 但内存 ulimits 较低的机器上。 Java decides to allocate a big heap because it detects the ram in the machine, but it's not allowed to allocate it because of ulimits. Java 决定分配一个大堆,因为它检测到机器中的 ram,但由于 ulimits 不允许分配它。

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 Variables->New: 变量名: _JAVA_OPTIONS变量值: -Xmx512M变量名: Path
    Variable value: %PATH%;C:\\Program Files\\Java\\jre6\\bin;F:\\JDK\\bin;变量值: %PATH%;C:\\Program Files\\Java\\jre6\\bin;F:\\JDK\\bin;

Change this to your appropriate path.将此更改为您的适当路径。

32-bit Java requires contiguous free space in memory to run. 32 位 Java 需要内存中连续的可用空间才能运行。 If you specify a large heap size, there may not be so much contiguous free space in memory even if you have much more free space available than necessary.如果指定较大的堆大小,则即使可用空间比所需的多得多,内存中也可能没有那么多连续的可用空间。

Installing a 64-bit version of Java helps in these cases, the contiguous memory requirements only applies to 32-bit Java.在这些情况下,安装 64 位版本的 Java 会有所帮助,连续内存要求仅适用于 32 位 Java。

Combined with -Xmx512M use -d64 to make sure you're running 64-bit VM.结合 -Xmx512M 使用 -d64 以确保您运行的是 64 位 VM。 On a 64-bit machine I thought for sure I was running 64-bit virtual machine, but no.在 64 位机器上,我确信我正在运行 64 位虚拟机,但没有。 After installing 64-bit Java the -d64 option works and -Xmx allows much larger memory sizes.安装 64 位 Java 后,-d64 选项起作用,-Xmx 允许更大的内存大小。

java -d64 -Xmx512M mypackage.Test

I got the same error and resolved this by configuring it in the run.conf.bat我遇到了同样的错误并通过在 run.conf.bat 中配置它来解决这个问题

Run the JVM with the configuring run.conf.bat in Jboss5x在 Jboss5x 中配置 run.conf.bat 运行 JVM

If free memory is not available AS you are passing in the statement then please make changes in run.conf.bat如果在您传入语句时没有可用内存,请在 run.conf.bat 中进行更改

set "JAVA_OPTS=-Xms512m -Xmx512m -XX:MaxPermSize=256m"

Open gradle.properties file in android folder.打开 android 文件夹中的 gradle.properties 文件。

Replace this line:替换这一行:

org.gradle.jvmargs=-Xmx1536M

with:和:

org.gradle.jvmargs=-Xmx512m

Explanation: Max limit from Gradle document:说明:来自 Gradle 文档的最大限制:

If the requested build environment does not specify a maximum heap size, the Daemon will use up to 512MB of heap.如果请求的构建环境没有指定最大堆大小,守护进程将使用最多 512MB 的堆。

I had similar issues.我有类似的问题。 I had installed 32 bit version of Java on a 64 bit machine.我在 64 位机器上安装了 32 位版本的 Java。

By uninstalling that version and installing 64 bit version of Java.通过卸载该版本并安装 64 位版本的 Java。 I was able to resolve the issue.我能够解决这个问题。

I know there are a lot of answers here already, but none of them helped me.我知道这里已经有很多答案了,但没有一个对我有帮助。 In the end I opened the file /etc/elasticsearch/jvm.options and changed:最后我打开文件/etc/elasticsearch/jvm.options并更改:

-Xms2G
-Xmx2G

to

-Xms256M
-Xmx256M

That solved it for me.那为我解决了。 Hopefully this helps someone else here.希望这可以帮助这里的其他人。

Sometimes, this error indicates that physical memory and swap on the server actually are fully utilized!有时,此错误表明服务器上的物理内存和交换实际上已被充分利用!

I was seeing this problem recently on a server running RedHat Enterprise Linux 5.7 with 48 GB of RAM.我最近在运行 RedHat Enterprise Linux 5.7 和 48 GB RAM 的服务器上看到了这个问题。 I found that even just running我发现即使只是跑步

java -version

caused the same error, which established that the problem was not specific to my application.导致了同样的错误,这表明问题并非特定于我的应用程序。

Running跑步

cat /proc/meminfo

reported that MemFree and SwapFree were both well under 1% of the MemTotal and SwapTotal values, respectively:据报道,MemFree 和 SwapFree 分别远低于 MemTotal 和 SwapTotal 值的 1%:

MemTotal:     49300620 kB
MemFree:        146376 kB
...
SwapTotal:     4192956 kB
SwapFree:         1364 kB

Stopping a few other running applications on the machine brought the free memory figures up somewhat:停止机器上其他一些正在运行的应用程序会使可用内存数字有所增加:

MemTotal:     49300620 kB
MemFree:       2908664 kB
...
SwapTotal:     4192956 kB
SwapFree:      1016052 kB

At this point, a new instance of Java would start up okay, and I was able to run my application.此时,一个新的 Java 实例将正常启动,并且我能够运行我的应用程序。

(Obviously, for me, this was just a temporary solution; I still have an outstanding task to do a more thorough examination of the processes running on that machine to see if there's something that can be done to reduce the nominal memory utilization levels, without having to resort to stopping applications.) (显然,对我来说,这只是一个临时解决方案;我仍然有一项出色的任务要对该机器上运行的进程进行更彻底的检查,看看是否可以采取一些措施来降低标称内存利用率水平,而不不得不求助于停止应用程序。)

Error :错误 :

For the error, "error occurred during initialization of vm could not reserve enough space for object heap jboss"对于错误, “在 vm 初始化期间发生错误,无法为对象堆 jboss 保留足够的空间”

Root Cause :根本原因 :

  • Improper/insufficient memory allocation to our JVM as mentioned below.如下所述,JVM 的内存分配不当/不足。

  • eg JAVA_OPTS="-Xms1303m -Xmx1303m -XX:MaxPermSize=256m" in jboss-eap-6.2\\bin\\standalone.conf or "JAVA_OPTS=-Xms1G -Xmx1G -XX:MaxPermSize=256M" in jboss-eap-6.2\\bin\\standalone.conf.bat which is nothing but JVM memory allocation pool parameters.例如,jboss-eap-6.2\\bin\\standalone.conf 中的JAVA_OPTS="-Xms1303m -Xmx1303m -XX:MaxPermSize=256m" 或jboss-eap-eap 中的"JAVA_OPTS=-Xms1G -Xmx1G -XX:MaxPermSize=256M" \\standalone.conf.bat 这只不过是 JVM 内存分配池参数。

Resolution :解决 :

  • Increase the heap size.增加堆大小。 To increase the heap size,要增加堆大小,
  • goto -> jboss-eap-6.2\\bin\\standalone.conf.bat or jboss-eap-6.2\\bin\\standalone.conf转到 -> jboss-eap-6.2\\bin\\standalone.conf.bat 或 jboss-eap-6.2\\bin\\standalone.conf
  • change ->JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=256m" where -Xms is Minimum heap size and -Xmx is Maximum heap size.更改 ->JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=256m" 其中 -Xms 是最小堆大小,-Xmx 是最大堆大小。
  • Usually its not recommanded to have same size for min and max.通常不建议 min 和 max 具有相同的大小。

  • If you are running your application from eclipse,如果您从 Eclipse 运行您的应用程序,

  • Double click on the server双击服务器
  • select 'open launch configuration' you will be redirected to the window 'Edit launch configuration properties'.选择“打开启动配置”,您将被重定向到“编辑启动配置属性”窗口。
  • In this windown goto the tab '(x)=Arguments'.在此窗口中,转到选项卡“(x)=Arguments”。
  • In VM Arguments, define your heap size as mentioned below在 VM Arguments 中,定义您的堆大小,如下所述
  • "-Dprogram.name=JBossTools: JBoss EAP 6.1+ Runtime Server" -server -Xms256m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true "-Dprogram.name=JBossTools: JBoss EAP 6.1+ 运行时服务器" -server -Xms256m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true

Suppose your class is called Test in package mypackage .假设您的类在包mypackage称为Test Run your code like this:像这样运行你的代码:

java -Xmx1024m mypackage.Test

This will reserve 1024 MB of heap space for your code.这将为您的代码保留 1024 MB 的堆空间。 If you want 512 MB, you can use:如果你想要 512 MB,你可以使用:

java -Xmx512m mypackage.Test

Use little m in 1024m , 512m , etc1024m512m等中使用小 m

I recently faced this issue.我最近遇到了这个问题。 I have 3 java applications that start with 1024m or 1280m heap size.我有 3 个以 1024m 或 1280m 堆大小开始的 Java 应用程序。 Java is looking at the available space in swap, and if there is not enough memory available, the jvm exits. Java 正在查看swap 中的可用空间,如果没有足够的可用内存,则jvm 退出。

To resolve the issue, I had to end several programs that had a large amount of virtual memory allocated.为了解决这个问题,我不得不结束几个分配了大量虚拟内存的程序。

I was running on x86-64 linux with a 64-bit jvm.我在带有 64 位 jvm 的 x86-64 linux 上运行。

If you're running 32bit JVM, change heap size to smaller would probabaly help.如果您正在运行 32 位 JVM,将堆大小更改为更小可能会有所帮助。 You can do this by passing args to java directly or through enviroment variables like following,您可以通过将 args 直接传递给 java 或通过如下环境变量来实现,

java -Xms128M -Xmx512M
JAVA_OPTS="-Xms128M -Xmx512M"

For 64bit JVM, bigger heap size like -Xms512M -Xmx1536M should work.对于 64 位 JVM,更大的堆大小(如-Xms512M -Xmx1536M应该可以工作。

Run java -version or java -d32 , java--d64 for Java7 to check which version you're running.为 Java7 运行java -versionjava -d32java--d64 d64 以检查您正在运行的版本。

I had right amount of memory settings but for me it was using a 64bit intellij with 32 bit jvm.我有适量的内存设置,但对我来说它使用的是带有 32 位 jvm 的 64 位 Intellij。 Once I switched to 64 bit VM, the error was gone.一旦我切换到 64 位 VM,错误就消失了。

Assuming you have enough free memory and you setup you JVM arguments correctly, you might have a problem of memory fragmentation.假设您有足够的空闲内存并且正确设置了 JVM 参数,您可能会遇到内存碎片问题。 Check Java maximum memory on Windows XP .检查Windows XP 上的 Java 最大内存

Anyway, 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无论如何,这里是如何修复它:转到开始->控制面板->系统->高级(选项卡)->环境变量->系统变量->新建:变量名称:_JAVA_OPTIONS变量值:-Xmx512M

OR或者

Change the ant call as shown as below.更改蚂蚁呼叫,如下所示。

   <exec
        **<arg value="-J-Xmx512m" />**
    </exec>

It worked for me.它对我有用。

Error occurred during initialization of VM Could not reserve enough space for 1572864KB object heap VM 初始化期间发生错误无法为 1572864KB 对象堆保留足够的空间

I changed value of memory in settings.grade file 1536 to 512 and it helped我将 settings.grade 文件 1536 中的内存值更改为 512,它有所帮助

Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System Variables->New:转到开始->控制面板->系统->高级(选项卡)->环境变量->系统变量->新建:

Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M

In case you are running a java program: - run your program in a terminal using the correct command for linux it would be 'java -jar myprogram.jar' and add -Xms256m -Xmx512m, for instance: 'java -jar myprogram.jar Xms256m -Xmx512m'如果您正在运行 Java 程序: - 在终端中使用正确的 linux 命令运行您的程序,它将是“java -jar myprogram.jar”并添加 -Xms256m -Xmx512m,例如:“java -jar myprogram.jar” Xms256m -Xmx512m'

In case you are running a .sh script (linux, mac?) or a .bat script (windows) open the script and look for the java options if they are present and increase the memory.如果您正在运行 .sh 脚本(linux、mac?)或 .bat 脚本(windows),请打开脚本并查找 java 选项(如果它们存在)并增加内存。

If all of the above doesn't work, check your processes (ctrl+alt+delete on windows) (ps aux on linux/mac) and kill the processes which use allot of memory and are not necessary for your operating system!如果以上所有方法都不起作用,请检查您的进程(windows 上的 ctrl+alt+delete)(linux/mac 上的 ps aux)并终止使用分配内存且对您的操作系统而言不是必需的进程! => Try to re-run your program. => 尝试重新运行您的程序。

In CASSANDRA_HOME/bin/cassandra.bat you would find following configuration在 CASSANDRA_HOME/bin/cassandra.bat 中,您会发现以下配置

REM JVM Opts we'll use in legacy run or installation
set JAVA_OPTS=-ea^
 -javaagent:"%CASSANDRA_HOME%\lib\jamm-0.3.0.jar"^
 -Xms**2G**^
 -Xmx**2G**^

You can reduce 2G to some smaller number for eg 1G or even lesser and it should work.您可以将 2G 减少到一些较小的数字,例如 1G 甚至更小,它应该可以工作。

Same if you are running on unix box, change in .sh file appropriately.如果您在 unix 机器上运行,请适当更改 .sh 文件。

Sometimes it relates as有时它与

$ sysctl vm.overcommit_memory
vm.overcommit_memory = 2

If you set it to:如果您将其设置为:

$ sysctl vm.overcommit_memory=0

It should work.它应该工作。

-Xmx2G替换为-Xms512M或 cassandra bin 目录中 cassandra.bat 文件中任何更大的内存大小。

我遇到了同样的错误,当我使用 %temp% 删除临时文件并重新启动 eclipse 时它得到了解决。

I am getting the following exception repeatedly each time I try to run the program.每次尝试运行该程序时,我都会反复收到以下异常。

Error occurred during initialization of VM VM初始化期间发生错误

Could not reserve enough space for object heap无法为对象堆保留足够的空间

Could not create the Java virtual machine.无法创建Java虚拟机。

I tried to increase my virtual memory (page size) and RAM size, but to no avail.我试图增加虚拟内存(页面大小)和RAM大小,但无济于事。

How can I eliminate this error?如何消除此错误?

In my case I couldn't increase org.gradle.jvmargs=-Xmx... in gradle.properties beyond 1GB.就我而言,我无法将 gradle.properties 中的gradle.properties org.gradle.jvmargs=-Xmx...增加到超过 1GB。 It didn't work because I had two Java installation on my machine, one 32 bit (Gradle was using this one) and the other 64 bit.它没有用,因为我的机器上安装了两个 Java,一个是 32 位的(Gradle 使用的是这个),另一个是 64 位的。 I resolved the problem by adding JAVA_HOME environment variable pointing to 64 bit Java.我通过添加指向 64 位 Java 的JAVA_HOME环境变量解决了这个问题。

No need to do anything just chnage in POM file like below无需做任何事情,只需在 POM 文件中更改如下所示

<configuration>
    <maxmemory>1024M</maxmemory>
</configuration>

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

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