Eclipse异常与java.lang.OutOfMemoryError:Java堆空间

时间:2013-11-06 19:17:33

标签: java eclipse

您好,我正在部分测试应用程序,它有堆空间问题。 这是示例代码

public class Test {


Test()
{
    byte[] b = new byte[744678306];
}


public static void main(String[] args) {
    // TODO Auto-generated method stub
    Test t=new Test();
}

}

错误

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

这是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

在vBox上工作环境:ubuntu 12。

谢谢你。

4 个答案:

答案 0 :(得分:4)

您要求的空间大约为750MB,但您的程序最多允许256,

查看this

只需在相应的运行配置中的VM参数列表中添加-Xmx2048M(对于2048 MB,您可以更改该数字)。

答案 1 :(得分:2)

您粘贴的Eclipse启动配置与您的问题无关。 Eclipse不会在自己的JVM中执行代码;它使用您在Eclipse 中明确指定的参数启动一个单独的JVM。

运行应用程序一次后,将为其创建“运行配置”条目。转到该条目(运行 - >配置...),然后在VM参数下,使用-Xmx指定更多内存。默认情况下,Java 7将mx设置为1 GB或总RAM的四分之一,以较小者为准。

答案 2 :(得分:1)

为避免内存不足错误,请执行以下步骤。 Eclipse - > run - > 运行配置 - > 参数。然后在VM参数中键入如下。

-XX:MaxHeapSize=1024m 

您可以指定自己的内存大小。

答案 3 :(得分:0)

我认为您在eclipse.ini中没有太多参数

这是Eclipse NEON和OS的最佳配置。配备4GB Ram的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

如果您有8GB的内存,请修改 -XX:PermSize = 512m -XX:MaxPermSize = 1024m 。 有关完整示例,请参见here