Pages

Eclipse – java.lang.OutOfMemoryError: Java heap space

In Eclipse IDE, if your program is consuming a lot of memory (loading big data)  then it will throw java.lang.OutOfMemoryError: Java heap space issue.
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.<init>(HashMap.java:209)

at java.util.LinkedHashMap.<init>(LinkedHashMap.java:181)

1. Solution – VM arguments

On Eclipse menu, clicks Run -> Run Configurations.., select the Java application you want to run, clicks on the Arguments tab, update the VM arguments with the following options
-Xms<size> - Set initial Java heap size
-Xmx<size> - Set maximum Java heap size

For example, -Xms512M -Xmx1024M


If you still face the java.lang.outofmemoryerror gc overhead limit exceeded eclipse

Steps to Solve the above issue in Eclipse
On Eclipse menu, clicks Run -> Run Configurations.., select the Java application you want to run, clicks on the Arguments tab, update the VM arguments with the following options

-Xms6144M -Xmx12288M 
-XX:+UseG1GC
-XX:+UseStringDeduplication

How to fix GC overhead limit exceeded in Eclipse

Another way to setup VMArguments in eclipseinstalaltion eclipse.ini

Memory is allocated via Eclipse' configuration file which is executed during Eclipse' startup. It is located in its installation directory and named eclipse.ini. The default values are good enough for small projects, but night not suffice for the bigger ones.
Below is a sample 'eclipse.ini file;
-startup
plugins/org.eclipse.equinox.launcher_1.5.300.v20190213-1655.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.1000.v20190125-2016
-product
org.eclipse.epp.package.jee.product
-showsplash
org.eclipse.epp.package.common
--launcher.defaultAction
openFile
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.8
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=1.8
-Dosgi.dataAreaRequiresExplicitInit=true
-Xms256m
-Xmx1024m
--add-modules=ALL-SYSTEM
Fixing the problem means allocating more memory for Eclipse. This could be done by increasing the values these parameters in the configuration file where the numbers represent the amount of memory to be allocated in megabytes (MB):
-Xms256m
-Xmx1024m

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.