11

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Ajinkya
  • 22,324
  • 33
  • 110
  • 161
  • 6
    *I know this is a exact duplicate of many questions* -- I suggest you then put a bounty on the questions you would like answered, or rephrase this question (provide specific details etc) so that it is *not* an exact duplicate. – aioobe Sep 12 '11 at 12:07
  • Have you considered the possibility for your app leaking memory? – Hyangelo Sep 12 '11 at 12:07
  • 4
    @Hyangelo: running out of PermGen is **not** the result of a simple memory leak. – Joachim Sauer Sep 12 '11 at 12:09
  • Under which circumstances does the exception occur, directly after startup or during a certain uptime? – home Sep 12 '11 at 12:09
  • @aioobe: I already have very less reputation to put bounty , will try if I dont get any solution. Which details I should add ? – Ajinkya Sep 12 '11 at 12:10
  • @home: Not after startup but while debugging – Ajinkya Sep 12 '11 at 12:10
  • 1
    You mixed up JVM configuration parameters. Does the problem occur in eclipse JVM (eclipse crash) or Tomcat JVM instance? If the latter, option #1 and #3 should not have any influence as they relate to the eclipse IDE JVM instance. – home Sep 12 '11 at 12:11
  • 1
    possible duplicate of [How to deal with "java.lang.OutOfMemoryError: PermGen space" error](http://stackoverflow.com/questions/88235/how-to-deal-with-java-lang-outofmemoryerror-permgen-space-error) - Because you *aren't* doing everything the answers there suggest. Specifically, *increasing the permgen size in tomcat* – Brian Roach Sep 12 '11 at 12:11
  • @home: Can you please explain me some details ? I see error on console and my eclipse dont crash. – Ajinkya Sep 12 '11 at 12:19
  • ...stupid question ...but isn't `eclipse.ini` there to set the flags for running eclipse itself, and not the applications you run/debug? – dagnelies Sep 12 '11 at 12:23
  • 1
    @arnaud: I know this is a stupid question and I am really a stupid guy to put this after knowing it. I tried whatever I found on the net as I am not expert enough to detect the silly errors.Will try to update my knowledge. Thanks. – Ajinkya Sep 12 '11 at 12:27

6 Answers6

25

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

home
  • 12,468
  • 5
  • 46
  • 54
3

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.

Ben
  • 13,297
  • 4
  • 47
  • 68
  • Should I remove -vmargs which I have mentioned in question ? – Ajinkya Sep 12 '11 at 12:14
  • I use this for JBoss AS, and added it to the startup script (the .bat on windows and .sh on linux). It should a parameter of your JVM startup so easiest to add it to JAVA_OPTS in tomcat startup script. – Ben Sep 12 '11 at 12:18
  • `Perm gen space isnt cleared by the Garbage Collector` - this is incorrect, and is true only of the CMS collector in it's default configuration. – Vineet Reynolds Sep 12 '11 at 12:22
  • I stand corrected, just read up on it abit here http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation and removed it from my post – Ben Sep 12 '11 at 12:32
0

For me -Xmx1024m -XX:MaxPermSize=256m did the trick.

kayz1
  • 7,260
  • 3
  • 53
  • 56
0

What tools have you used to profile your running application? I recommend using eclipse mat, although jconsole and visualvm are available with the jdk. Do you load a lot of classes in your application, somewhere in a loop? How about strings? what is the size of the string pool? I am sorry but restarting tomcat, eclipse or the machine is not going to solve the problem; you will need to profile and analyse your application to solve the issue. Take a heap dump (you can use jmap) and analyse.

Scorpion
  • 3,938
  • 24
  • 37
0

I would add -XX:PermSize=1024m in the JAVA_OPTS variable, as the error might come from Tomcat. I'm not familiar with the eclipse.ini file.

Romeo
  • 337
  • 1
  • 6
  • 17
0

I don't know the details about eclipse.ini but I though this was just to set flags when starting Eclipse itself. Without impact on running/debugging applications. Personally, whenever I want to alter the settings when running/debugging an application, I simply add the JVM flags in the corresponding run/debug configuration.

Moreover, if you use more than 1 giga perm space, I guess there's something wrong in the code. Try to locate the source of the perm space consumption and fix it. I don't say it'll be easy, but it'll be needed in order for the application to work properly. ...except if 1 giga perm space is really intended, but i've some doubts about it.

What you can look for is for example string.intern(). If you do this on each request/entry/whatever for arbitrary strings, you'll uselessly fill your perm space since it'll permanently keep a copy of the string.

dagnelies
  • 5,203
  • 5
  • 38
  • 56
  • Thnaks for the suggestion. I kept my heap and permgen size as 512. What exactly you mean by your "eclipse config and your tomcat config don't match" ? – Ajinkya Sep 12 '11 at 12:24
  • Your tomcat `JAVA_OPTS` have different values for min/max heap, perm size and GC policy than your `eclipse.ini` config. – dagnelies Sep 12 '11 at 12:27
  • @Ajinkya: have you tried to just put -XX:MaxPermSize=512m to the run/debug configuration of your application? (the small arrow on the right of the play/debug icon -> end of the menu -> arguments tab -> VM arguments) – dagnelies Sep 12 '11 at 12:30
  • My new values `set JAVA_OPTS=-XX:NewSize=512m -XX:MaxNewSize=1024m -XX:PermSize=128m -XX:MaxPermSize=512m -XX:+DisableExplicitGC -Xms512m -Xmx1024m` and `-vmargs -Dosgi.requiredJavaVersion=1.5 -Xms512m -Xmx1024m -XX:MaxPermSize=512m` – Ajinkya Sep 12 '11 at 12:31
  • before you poke around with everything, you should first try to understand what you are actually doing. Have you set the JVM arguments properly at all? Like in: http://wiki.eclipse.org/images/6/65/UML2Tools_Run_Eclipse_Application_VM_Parameters.JPG – dagnelies Sep 12 '11 at 12:38