Program throws "java.lang.OutOfMemoryError" in Eclipse

In Eclipse, if the program doesnot get the required memory it throws "java.lang.OutOfMemoryError: Java heap space". For e.g. in my threaded program it throws:
Exception in thread "Thread-29" java.lang.OutOfMemoryError: Java heap space
 at java.util.HashMap.(Unknown Source)
 at weblogic.xml.util.LLNamespaceMap.(LLNamespaceMap.java:16)
................
................
Exception in thread "Thread-33" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Thread-26" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Thread-13" java.lang.OutOfMemoryError: Java heap space

We can fix this in Eclipse VM arguments.
On Eclipse menu, go to Run -> Run Configurations...
In the corresponding "Run Configurations" window select the Java Application that you intend to modify(this might be default selected if you have just ran the program).
Then click on the "Arguments" tab, and edit/add the "VM arguments" with "-Xms512M -Xmx1024M".
This will increase the VM heap size to minimum 512MB and a max of 1GB. Click "Apply" and "Run".


No comments:

Post a Comment