10 Replies Latest reply on Feb 12, 2010 8:32 AM by Kirpal Singh

    Perm gen space (OutOfMemoryError)

    Geoffrey De Smet Newbie

      After deploying my exploded seam ear a couple of times from Intellij, JBoss 4.2.2 always crashes with a perm gen space OutOfMemoryError. Is there any way to avoid that?

        • 1. Re: Perm gen space (OutOfMemoryError)
          Shane Bryzak Master

          From chapter 2 of the Seam ref docs:




          JBoss has sophisticated support for hot re-deployment of WARs and EARs. Unfortunately, due to bugs in the JVM, repeated redeployment of an EAR—which is common during development—eventually causes the JVM to run out of perm gen space. For this reason, we recommend running JBoss in a JVM with a large perm gen space at development time. If you're running JBoss from JBoss IDE, you can configure this in the server launch configuration, under "VM arguments". We suggest the following values:


          -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512



          • 2. Re: Perm gen space (OutOfMemoryError)
            Geoffrey De Smet Newbie

            Thanks, I missed that in the manual.


            I don't have enough physical memory on this pc.
            Has anyone experimented with embedding Seam and EJB3 in Jetty?
            Could Jetty initialize faster (with less memory) than hot deploying to JBoss?


            I like Seam, but the JBoss AS just seems way to heavy for what I need. I tried running JBoss with the minimal profile, but that doesn't support EJB3. On the other hand, if I use the default profile, it takes a long time to boot and starts services that I don't need (SOAP etc).

            • 3. Re: Perm gen space (OutOfMemoryError)
              Shane Bryzak Master

              Do your components need to be EJBs?  If not, you can just deploy to Tomcat (or possibly Jetty, I haven't tried it) without EJB support, which would require a smaller memory footprint.

              • 4. Re: Perm gen space (OutOfMemoryError)
                Stephen Friedrich Novice

                Concerning bugs in the JVM: Can you point me to an entry in Sun's bug tracker?
                To me it sounds like an easy excuse for JBoss.


                I have spent quite some time looking for the culprit, but unfortunately while profiling I got lost in the implementation details of tomcat/jboss as/hibernate/seam.


                At my current workplace the only projects that are suffering from this problem are those that use hibernate/seam/jsf.
                Other projects that use Spring and plain JDBC and JSPs are not having this issue.


                My latest project uses Tomcat (without EJB). While the total war size is smaller, it still is 15 MB and is triggering the problem on the fourth redeployment.


                The main problem is that it is quite some administrational overhead to get the production servers restarted or reconfigured (with bigger perm gen). Plus in the end it's me who makes a bad impression, because other projects are not having this problem.


                Here are some links describing the issue and possible solutions:


                The java.lang.OutOfMemoryError: PermGen Space error demystified


                How to fix the dreaded java.lang.OutOfMemoryError: PermGen space exception


                Memory leak - classloader won't let go



                • 5. Re: Perm gen space (OutOfMemoryError)
                  Dan Allen Master

                  There is so much misinformation about this topic that its difficult to even have a sensible conversation about it. The problem is really quite simple. The Sun JVM uses the permanent generation to store class files, but the permanent generation is not sweeped by the garbage collector. Each time you redeploy your app, the permenant generation gets bigger and eventually it bursts, regardless of how big you make it. A bigger size just prolongs the inevitable.


                  You have two options. You can enable sweeping of the permanent generation.


                  -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled


                  Or you can switch to a JVM that does not use a permanent generation (or doesn't use it to store class files) like the IBM JVM. In fact, we ran the IBM JVM in production for 2 years and NEVER got an out of memory error.


                  The problem is NOT with JBoss AS. You will see the same problem with Tomcat eventually. The problem is with the garbage collector strategy not aligning with how web applications are redeployed.

                  • 6. Re: Perm gen space (OutOfMemoryError)
                    Stephen Friedrich Novice

                    the permanent generation is not sweeped by the garbage collector. Each time you redeploy your app, the permenant generation gets bigger

                    IMHO that is misinformation, too.


                    Even without any VM options set classes get garbage collected when their ClassLoader instance gets garbage collected.
                    The ClassLoader instance (which is not part of the permgen) is elligible for garbage collection when all instances of classes loaded by that class loader are unreachable.


                    Unfortunately it is way too easy to accidentally make an object reachable, which prevents garbage collection of all classes. (Not exiting a thread, storing references to application classes in classes loaded by other class loaders, ...)


                    The options you gave simply mitigate the problem a little because they allow a class to get garbage collected even while its class loader is still alive.

                    • 7. Re: Perm gen space (OutOfMemoryError)
                      Mark Coffin Newbie


                      -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled



                      Even with these parameters our JBoss application server still does not release the resources.


                      I've also read the IBM's JVM doesn't actually resolve the problem.  You'll probably not get a PermGen OutofMemory exception, from what I read IBM's JVM will just keep Allocating more memory and eventually you'll have gig's of PermGen space.


                      Have a look here.


                      It's also really hard to track down where the problem actually is.
                      With JDK 6, you might be able to it down.  Have a look here.


                      Hope this helps, I haven't had the chance to sit down and try and resolve these problems with our app. yet.



                      • 8. Re: Perm gen space (OutOfMemoryError)
                        Jason Long Novice

                        I use JRockit to avoid this.  I have never seen this error since I switched.


                        However, I cannot find the link to download JRockit anymore.  I still have a copy, but where is the link?


                        It still claims to be a free download on the page, but none of the links work.


                        Has anyone heard anything about this?  Is oracle screwing up things already?

                        • 9. Re: Perm gen space (OutOfMemoryError)
                          Krum Tsvetkov Newbie

                          Hi,


                          you may find this blog on the topic interesting. It describes how to analyze some of the perm space related problems with the Memory Analyzer tool from Eclipse.




                          • 10. Re: Perm gen space (OutOfMemoryError)
                            Kirpal Singh Newbie

                            Hello together,


                            I have one issue. We are using a Jetty server for testing our applications. Yesterday we were getting an error, the so called: WARN:  handle failed java.lang.OutOfMemoryError: PermGen space


                            We tried solving this problem by increasing the physical memory (RAM) to higher values like this:


                            JAVAOPTIONS: -Xmx2048m -Xms1024m -XX:PermSize256m -XX:MaxPermSizeunderscore512m


                            Having made these changes we were able to run the server but after about half an hour it went down.


                            I searched for some solution in the net and got to know that one should place three new parameters in order to rectify this issue. So we put the following parameters:
                            XX:..UseConcMarkSweepGC
                            -XX:..CMSPermGenSweepingEnabled
                            -XX:..CMSClassUnloadingEnabled


                            But having made these changes we got the following error message:


                            Please use CMSClassUnloadingEnabled in place of CMSPermGenSweepingEnabled in the future.


                            So we just put only one parameter namely CMSClassUnloadingEnabled. Having done this we were able to solve our problem. I mean, the server was running without any problem and that too for couple of hours.


                            The topic doesn't stop there. A colleague of us, told us, it is too (!) dangerous to have such parameter. So we have to remove the CMSClassUnloadingEnabled parameter.


                            Now my questions to you:
                            -       Could you please through some light on this issue. Is it really dangerous to have such parameter?
                            -       Is there some other workaround for the same problem?
                            -       (last question of the day) Is there way out to calculate the maximum (or minimum as per the case) value for the parameters: Xmx, Xms, PermSize, MaxPermSize? We have a total physical memory of 4 GB. Today morning we tried with the following values for the different parameters:


                            -Xmx 3072m -Xms 3072m -XX:PermSize 1024m -XX:MaxPermSize 1024m


                            But the server didn't run. So we again decreased the above values to


                            -Xmx 2084m -Xms 2084m -XX:PermSize 512m -XX:MaxPermSize 512m


                            and it was (and is still) running again.


                            I would be highly obliged if you could please assist us in this concern.


                            Thanking you in anticipation.


                            Best regards,


                            Kirpal


                            PS: wherever I have put an underscore it actually stands for an equal sign
                                .. stands for a plus sign