java.lang.OutOfMemoryError 的 Eclipse 异常:Java 堆空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19820824/
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
Eclipse Exception with java.lang.OutOfMemoryError: Java heap space
提问by draford
Hi I am partially testing an application and It has a problem with heap space. Here is sample code
嗨,我正在部分测试一个应用程序,它有一个堆空间问题。这是示例代码
public class Test {
Test()
{
byte[] b = new byte[744678306];
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test t=new Test();
}
}
Error
错误
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Here is eclipse ini configuration
这里是eclipse ini配置
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.1.200.v20130807-1835
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=256m
-Xms800m
-Xmx999m
Working env : ubuntu 12 on vBox.
工作环境:vBox 上的 ubuntu 12。
Thanks advance.
先谢谢了。
采纳答案by cangrejo
You are asking for space for about 750MB, but your program starts with a maximum allowed of 256,
您要求大约 750MB 的空间,但您的程序开始时最大允许为 256,
Take a look at this
看看这个
Just add -Xmx2048M (for 2048 MB, you can change that number) in the list of VM arguments in the corresponding run configuration.
只需在相应运行配置的 VM 参数列表中添加 -Xmx2048M(对于 2048 MB,您可以更改该数字)。
回答by Marko Topolnik
The Eclipse startup configuration which you have pasted has nothing to do with your problem. Eclipse does not execute your code in its own JVM; it starts a separate JVM with the arguments you explicitly specify within Eclipse.
您粘贴的 Eclipse 启动配置与您的问题无关。Eclipse 不会在其自己的 JVM 中执行您的代码;它使用您在 Eclipse 中明确指定的参数启动一个单独的 JVM 。
After you run the application once, a Run Configuration entry will be created for it. Go to that entry (Run -> Configurations...) and, under VM arguments, specify more memory with -Xmx
. By default, Java 7 sets mx
to 1 GB or a quarter of the total RAM, whichever is less.
运行应用程序一次后,将为其创建一个运行配置条目。转到该条目(运行 -> 配置...),然后在 VM 参数下,使用-Xmx
. 默认情况下,Java 7 设置mx
为 1 GB 或总 RAM 的四分之一,以较小者为准。
回答by sashikanta
For avoiding the out of memory error do the following steps. Eclipse-> run-> run configuration-> arguments. Then in VM arguments type as below.
为避免内存不足错误,请执行以下步骤。Eclipse-> run-> run configuration-> arguments。然后在 VM 参数中键入如下。
-XX:MaxHeapSize=1024m
You can specify your own memory size.
您可以指定自己的内存大小。
回答by Rosario Mezzatesta
I think you don't have many parameter in eclipse.ini
我认为你在 eclipse.ini 中没有很多参数
This is the best configuration for Eclipse NEON and o.s. Windows 10 with 4GB of Ram:
这是带有 4GB 内存的 Eclipse NEON 和 os Windows 10 的最佳配置:
-startup
plugins/org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.401.v20161122-1740
-product
org.eclipse.epp.package.jee.product
–launcher.defaultAction
openFile
–launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
–launcher.defaultAction
openFile
-vm
C:/Program Files/Java/jdk1.8.0_121/bin/javaw.exe
–launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.8
-Xms256m
-Xmx512m
-XX:PermSize=256m
-XX:MaxPermSize=512m
If you have 8GB of Ram modify -XX:PermSize=512mand -XX:MaxPermSize=1024m. For complete example see here.
如果您有 8GB 的 Ram 修改-XX:PermSize=512m和-XX:MaxPermSize=1024m。有关完整示例,请参见此处。