was的java heap space_Eclipse java.lang.OutOfMemoryError: Java heap space

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

List 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.(HashMap.java:209)

at java.util.LinkedHashMap.(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 - Set initial Java heap size

-Xmx - Set maximum Java heap size

For example, -Xms512M -Xmx1024M

591098585f1f0dbd0b2c96b9cc204d08.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值