Eclipse "java.lang.OutOfMemoryError" on Ubuntu

There are two common reasons for Eclipse to throw "java.lang.OutOfMemoryError"

  1. Heap space is to small
  2. Permgen size (permanent generation space) is to small

Heap space is where your java objects are created, maintained, and destroyed. Without going into too many details about how exactly heap space regulates java objects. Here is a quick fix for the "OutOfMemoryError" error in Ubuntu.

  • Go to the eclipse.ini file:
    • cd usr/lib/eclipse
    • sudo vim eclipse.ini
  • The Original heap space has 40MB and a maximum of 256MB. Increase Xms and Xmx based on your need
  • save and quit from eclipse.ini

However, if you still get an "OutOfMemoryError" error, even though your heap space is under utilized, one possible cause would be that your "Permanent Generation" space is too small. Permanent Generation space is a place where the actual classes (not the instances) reside. The JVM uses the classes in Permanent Generation space to to creates instances to put into the heap space. Depending on the versions of JVM, if the permanent generation space is too small, some JVM (1.4.x) will unload the classes from here, which will affect runtim performance or some JVM (1.3.x)simply do nothing to the existing classes in the permanent generation space, in which case you will need to increase the size of the permanent generation space in eclipse.ini

  • Change the following line in the /usr/lib/eclipse/eclipse.ini:
    • --launcher.XXMaxPermSize 256m