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.

draford
  • 243
  • 1
  • 3
  • 15

4 Answers4

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.

Community
  • 1
  • 1
cangrejo
  • 2,189
  • 3
  • 24
  • 31
2

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.

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.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
1

For avoiding the out of memory error do the following steps. Eclipse -> run -> run configuration -> arguments. Then in VM arguments type as below.

-XX:MaxHeapSize=1024m 

You can specify your own memory size.

blo0p3r
  • 6,790
  • 8
  • 49
  • 68
sashikanta
  • 341
  • 5
  • 19
0

I think you don't have many parameter in eclipse.ini

This is the best configuration for Eclipse NEON and o.s. Windows 10 with 4GB of Ram:

-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=512m and -XX:MaxPermSize=1024m. For complete example see here.