Eclipse java.lang.OutOfMemoryError: Java heap space

摘要: In Eclipse IDE, if your program is consuming a lot of memory (loading big data) like this :

In Eclipse IDE, if your program is consuming a lot of memory (loading big data) like this :

  List<Domain> list = domainBo.findAllDomain(100000);
  for(Domain domain : list){
	process(domain.getDomainName());

It can easily hit java.lang.OutOfMemoryError: Java heap space :

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

2. Mistake – eclipse.ini

The memory settings in eclipse.ini is allocated to Eclipse IDE only, not the program you want to run. A very common mistake is updated the heap size in eclipse.ini, and expects it to solve above out of memory problem.

Note
The Java application, Ant / Maven build scripts, or unit test cases, are run as an external tool from Eclipse, and it does not inherit the VM settings in eclipse.ini.

But, if your Eclipse IDE is always crashed by no reason, you can try to increase the heap size and perm gen in eclipse.ini.

/Users/mkyong/Downloads/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini
	
	-startu
	openFile
	-showsplash
        //...
	-XX:MaxPermSize=512m
	-Xms512m
	-Xmx1024m
        //...
	-Xdock:icon=../Resources/Eclipse.icns
	-XstartOnFirstThread

P.S eclipse.ini is located in the Eclipse installation folder.

References

  1. FAQ How do I increase the permgen size available to Eclipse?
  2. Find Out Your Java Heap Memory Size
  3. Eclipse + Tomcat – Java.Lang.OutOfMemoryError: Java Heap Space

上一篇: Ant and TestNG Task example
下一篇: jQuery and Java List example
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号