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.

11
  • 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. Commented Sep 12, 2011 at 12:07
  • 4
    @Hyangelo: running out of PermGen is not the result of a simple memory leak. Commented Sep 12, 2011 at 12:09
  • 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. Commented Sep 12, 2011 at 12:11
  • 1
    possible duplicate of 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 Commented Sep 12, 2011 at 12:11
  • 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. Commented Sep 12, 2011 at 12:27

6 Answers 6

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

Sign up to request clarification or add additional context in comments.

1 Comment

@Ajinkya: No prob, I fought that war one year ago or so :-) So it did work?
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.

4 Comments

Should I remove -vmargs which I have mentioned in question ?
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.
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.
I stand corrected, just read up on it abit here blogs.oracle.com/jonthecollector/entry/… and removed it from my post
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.

Comments

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.

Comments

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.

5 Comments

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" ?
Your tomcat JAVA_OPTS have different values for min/max heap, perm size and GC policy than your eclipse.ini config.
@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)
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
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: wiki.eclipse.org/images/6/65/…
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.