Eclipse 中的“Java 运行时环境内存不足”消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22805552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:01:03  来源:igfitidea点击:

"insufficient memory for the Java Runtime Environment " message in eclipse

javaeclipse

提问by Balaram26

When I run my Java code in Eclipse, I get the following message:

当我在 Eclipse 中运行我的 Java 代码时,我收到以下消息:

There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (malloc) failed to allocate 4088 bytes for AllocateHeap
An error report file with more information is saved as:
E:\Eclipse_Workspace\BTest\hs_err_pid1888.log

I have 4GB RAM in my computer. I have changed my JRE from 1.7 to 1.8 too. But the issue seems un-resolved. I use a Win 8 system with i3 Processor and have around 20gb of free disk space in my C Drive.

我的电脑有 4GB 内存。我也将 JRE 从 1.7 更改为 1.8。但问题似乎没有解决。我使用带有 i3 处理器的 Win 8 系统,并且我的 C 驱动器中有大约 20GB 的可用磁盘空间。

Eclipse version: Eclipse Juno Service release 2

Eclipse 版本:Eclipse Juno 服务版本 2

I also get this message while starting Eclipse. I have attached the error message screen shot.

我在启动 Eclipse 时也收到此消息。我附上了错误消息屏幕截图。

What is causing this issue?

是什么导致了这个问题?

enter image description here

在此处输入图片说明

Memory parameters in "eclipse.ini" file:

“eclipse.ini”文件中的内存参数:

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120913-144807
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-Xms40m
-Xmx512m

Resolution:Re-installing eclipse fixed the problem.

解决方案:重新安装 eclipse 解决了该问题。

回答by Harmlezz

In your Eclipseinstallation directory you should be able to find the file eclipse.ini. Open it and find the -vmargssection. Adjust the value of:

在您的Eclipse安装目录中,您应该能够找到该文件eclipse.ini。打开它并找到该-vmargs部分。调整以下值:

-Xmx1024m

In this example it is set to 1GB.

在本例中,它设置为 1GB。

回答by Ojonugwa Jude Ochalifu

Your application (Eclipse) needs more memory and JVM is not allocating enough.You can increase the amount of memory JVM allocates by following the answers given here

您的应用程序 (Eclipse) 需要更多内存,而 JVM 没有分配足够的内存。您可以按照此处给出的答案增加 JVM 分配的内存量

回答by Aaron Digulla

The message above means that you're running so many programs on your PC that there is no memory left to run one more. This isn't a Java problem and no Java option is going to change this.

上面的消息意味着您在 PC 上运行了太多程序,以至于没有剩余内存可以再运行一个。这不是 Java 问题,没有 Java 选项会改变这一点。

Use the Task Manager of Windows to see how much of your 4GB RAM is actually free. My guess is that somewhere, you have a program that eats all the memory. Find it and kill it.

使用 Windows 的任务管理器查看您的 4GB RAM 中有多少实际上是空闲的。我的猜测是在某个地方,您有一个程序会占用所有内存。找到它并杀死它。

EDITYou need to understand that there are two types of "out of memory" errors.

编辑您需要了解有两种类型的“内存不足”错误。

The first one is the OutOfMemoryException which you get when Java code is running and the Java heapis not large enough. This means Java codeasks the Java runtimefor memory. You can fix those with -Xmx...

第一个是 OutOfMemoryException,当 Java 代码正在运行并且 Java不够大时,您会得到它。这意味着 Java代码向 Java运行时请求内存。你可以用-Xmx...

The other error is when the Java runtimeruns out of memory. This isn't related to the Java heap at all. This is an error when Java asks the OS for more memory and the OS says: "Sorry, I don't have any."

另一个错误是 Java运行时内存不足。这是不相关的Java堆在所有。当 Java 要求操作系统提供更多内存并且操作系统说:“抱歉,我没有内存”时,这是一个错误。

To fix the latter, close applications or reboot (to clean up memory fragmentation).

要修复后者,请关闭应用程序或重新启动(以清理内存碎片)。

回答by Mind Peace

Try to modify your eclipse.ini with below

尝试使用以下内容修改您的 eclipse.ini

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120913-144807
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
512M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-Xms2G
-Xmx3G
-XX:MaxPermSize=2G
-XX:+UseCompressedOops
-XX:+UseParallelGC

Once you open your eclipse you can try below

打开日食后,您可以尝试以下操作

Looks like your application consumes more memory than allocated (Default). I will try two things

看起来您的应用程序消耗的内存多于分配的内存(默认)。我会尝试两件事

  1. As suggested by Harmlezz increase your memory allocation to JVM to -Xms2g -Xmx2g (If needed increase it more and try it out)

  2. Download eclipse memory analyzer and check for what causing memory leak OR even you can use JConsole to see JVM memory utilization in order to figure out application memory leak issue.

  1. 正如 Harmlezz 所建议的,将您对 JVM 的内存分配增加到 -Xms2g -Xmx2g(如果需要增加更多并尝试一下)

  2. 下载 eclipse 内存分析器并检查导致内存泄漏的原因,或者您甚至可以使用 JConsole 查看 JVM 内存利用率以找出应用程序内存泄漏问题。

回答by Eric Leschinski

How to diagnose this error even when running the simple command:

即使在运行简单命令时如何诊断此错误:

java -version
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Cannot create GC thread. Out of system resources.
# An error report file with more information is saved as:
# /home2/ericlesc/code/java/c2/hs_err_pid23944.log

Check the amount of free memory you have:

检查您拥有的可用内存量:

free -m
             total       used       free     shared    buffers     cached
Mem:         28119      26643       1475        189       2391      15368
-/+ buffers/cache:       8884      19235
Swap:         5117         34       5083

Check the max number of user processes, make sure you are not over limit:

检查最大用户进程数,确保您没有超过限制:

ulimit -a

ps -ef | wc -l

For me, the reason this happened was because PHP had consumed too much memory allocated to me on bluehost, and the way I was able to fix it, without restarting PHP or the server ( I can't ) was to take the public_htmldirectory and rename it. And give it a minute for PHP to see the change, then rename it back.

对我来说,发生这种情况的原因是 PHP 在 bluehost 上消耗了太多分配给我的内存,而我能够在不重新启动 PHP 或服务器(我不能)的情况下修复它的方法是获取public_html目录并重命名它。并给它一分钟让 PHP 看到更改,然后将其重命名。

A bug in the php engine itself. I found a clever way to give the PHP engine a swift kick.

php 引擎本身的一个错误。我找到了一种巧妙的方法来快速启动 PHP 引擎。

(update Feb 2016)(I'm getting a spike of up-votes on this because Bluehost instance PHP engines are reserving all the memory and leaving none for the JVM. In their defense, PHP is evolving into an unholy rube Goldberg machine. Bluehost as a service is on the decline.

(2016 年 2 月更新)(因为 Bluehost 实例 PHP 引擎正在为 JVM 保留所有内存,并且没有为 JVM 保留任何内存,因此我对此获得了大量支持。在他们的辩护中,PHP 正在演变成一个邪恶的 rube Goldberg 机器。Bluehost作为一项服务正在下降。

回答by R Karwalkar

If you are on ec2 and wanted to do mvn build then use -T option which tells maven to use number of threads while doing build

如果你在 ec2 上并且想要做 mvn build 然后使用 -T 选项告诉 maven 在做构建时使用线程数

eg:mvn -T 10 clean package

例如:mvn -T 10 clean package

回答by Amit Gurbani

If you are using Virtual Machine (VM), allocate more RAM to your VMand your problem will be solved.

如果您使用的是虚拟机 (VM),请为您的 VM 分配更多 RAM,您的问题将得到解决。

回答by rab

You need to diagnosis the jvm usages like how many process is running and what about heap allocation. there exists a lot of ways to do that for example

您需要诊断 jvm 使用情况,例如正在运行的进程数量以及堆分配情况。例如,有很多方法可以做到这一点

  • you can use java jcmd to check number of object, size of memory (for linux you can use for example "/usr/jdk1.8.0_25/bin/jcmd 19628 GC.class_histogram > /tmp/19628_ClassHistogram_1.txt", here 19628 is the running application process id). You can easily check if any strong reference exists in your code or else.
  • 您可以使用 java jcmd 检查对象数量、内存大小(对于 linux,您可以使用例如“/usr/jdk1.8.0_25/bin/jcmd 19628 GC.class_histogram > /tmp/19628_ClassHistogram_1.txt”,这里 19628 是正在运行的应用程序进程 ID)。您可以轻松检查代码中是否存在任何强引用或其他。

回答by Marzouk

I know the question talking about eclipse but i got the similar issue many times with Intellij as well and the solution for it was easy .. Just run the 64 bit exe not the 32 one which is always the default one.

我知道关于 eclipse 的问题,但我在 Intellij 上也多次遇到类似的问题,解决方案很简单。只需运行 64 位 exe,而不是 32 位 exe,而 32 位 exe 始终是默认的。

回答by Nae

In my case it was that the C: drive was out of space. Ensure that you have enough space available.

就我而言,是 C: 驱动器空间不足。确保您有足够的可用空间。