Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.OutOfMemoryError: PermGen space

Question: I am using eclipse-helios and Tomcat 6 for my spring application and get

java.lang.OutOfMemoryError: PermGen space  

WHENEVER I DEBUG MY APPLICATION

I tried

  1. Adding

    -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms512m -Xmx1024m -XX:MaxPermSize=1204m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
    to eclipse.ini

  2. Creating setenv.sh and setenv.bat in tomcat_home/bin with following content

    set JAVA_OPTS="-Xms256m -Xmx512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"

  3. Manually running garbage collector in eclipse. I enabled this option by

    Window -> Preferences -> General -> and select always run in background and show heap status

  4. Restarting Tomcat hundred times.

  5. Restarting eclipse and sometimes restarting my machine when frustration goes beyond the limit..

Best part is I still get the error. Is there any solution which I should try?


I tried running other application and still get same error also IMHO my application is too small to cause error and my app is running fine on my colleagues setup.

like image 369
Ajinkya Avatar asked Sep 12 '11 12:09

Ajinkya


2 Answers

Your first 3 options target 2 different JVMs. Options #1 and #3 modify eclipse JVM instance, this is the JVM managing your IDE. Option #2 modifies the Tomcat JVM instance. That's why you see two java.exe files in your task manager (in case of windows) when starting eclipse and Tomcat (assuming those are the only Java apps running).

It's important to understand that the Tomcat plugins provided by eclipse WTP (in my case Indigo) do not call the external (OS dependent) scripts to start/stop Tomcat. Instead they spawn the Tomcat JVM directly via the command line (java.exe ...). If you want to modify JVM parameters for Tomcat instances you start from within eclipse it is necessary to modify the corresponding Run Configuration. Try modifying the JVM parameters there, it should work (see screenshot). enter image description here

like image 194
home Avatar answered Oct 19 '22 17:10

home


Try set JAVA_OPTS=-XX:NewSize=128m -XX:MaxNewSize=256m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -Xms512m -Xmx1536m

The permanent generation is special because it holds meta-data describing user classes (classes that are not part of the Java language). Examples of such meta-data are objects describing classes and methods and they are stored in the Permanent Generation. Applications with large code-base can quickly fill up this segment of the heap which will cause java.lang.OutOfMemoryError: PermGen no matter how high your -Xmx and how much memory you have on the machine.

like image 42
Benjamin Udink ten Cate Avatar answered Oct 19 '22 17:10

Benjamin Udink ten Cate