1

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

-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.

Thanks advance.

4

4 回答 4

4

You are asking for space for about 750MB, but your program starts with a maximum allowed of 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.

于 2013-11-06T19:22:03.930 回答
2

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

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

于 2013-11-06T19:29:58.707 回答
1

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

-XX:MaxHeapSize=1024m 

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

于 2014-09-18T17:54:54.137 回答
0

我认为你在 eclipse.ini 中没有很多参数

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

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

于 2018-07-23T08:17:20.417 回答