Grails: java.lang.OutOfMemoryError: PermGen space

Use case

Developing with IntelliJ and Grails sometimes leads to memory problems, particularly considering the PermGen space – even with plenty of RAM. This issue occures especially after re-deploying several times while debugging.

Incident

This is more a flaw with Tomcat itself, rather then Grails or any framework components – though Grail’s ”convention over coding” guide line heads to the problem by using reflection to help enforce.  And reflection does use perm gen to do it’s work.

If you are using JBoss I’d recommend Dror Bereznitsky’s blog post, he discusses this topic in depth.

This is how the exception looks like:

java.lang.OutOfMemoryError: PermGen space
Error automatically restarting container: java.lang.OutOfMemoryError: PermGen space
2010-08-03 14:53:38,208 [http-8080-52] ERROR [/SampleTemplateApp].[grails] - Servlet.service() for servlet grails threw exception
java.lang.OutOfMemoryError: PermGen space
2010-08-03 14:53:38,211 [http-8080-52] ERROR [/SampleTemplateApp].[default] - Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
2010-08-03 14:53:38,213 [http-8080-52] ERROR [Tomcat].[localhost] - Exception Processing ErrorPage[errorCode=500, location=/grails-err
orhandler]

Solution

Now you might find a lot of blogs and posts where one recommend to configure the JVM options to provide more RAM for the Perm itself.

-XX:MaxPermSize=512m
-XX:PermSize=128m

But this will only delay the problem,  not vanish. The point is, that Tomcat does not clean up the PermGen (Permanent Generation) and so it grows and grows with every hot re-deployment.

To get rid of this annoying circumstance you might want to enable both the unloading of the PermGen and its sweeping. This can be done as follow:

-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled

For IntelliJ users:

There are two options to configure IntelliJ to use this VM-args:

1. Project:
You can set those parameters in the debug/run configuration for each individual project as shown in the screenshot (debug configuration).

IntelliJ Grails VM Parameter

2. General:
Update the idea.vmoptions located in /idea-IU-xxx/bin/.

The latter approach has the advantage that it automatically affects all existing grails projects, and certainly all prospective as well.

Update #1

Unfortunately I’m still facing the memory issues in developing mode, even with project-wide configured PermGen arguments. I guess I have to try different approaches..

Currently I’m checking if this might help anything: http://docs.oracle.com/cd/E13209_01/wlcp/wlss30/configwlss/jvmgc.html

-server
-XX:MaxPermSize=256m
-XX:+UseParNewGC
-XX:MaxNewSize=256m
-XX:NewSize=256m
-Xms768m
-Xmx1024m
-XX:SurvivorRatio=128
-XX:MaxTenuringThreshold=0
-XX:+UseTLAB
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled

Update #2

After a couple of weeks I recognized that the solution mentioned above works like a charm in my case. I can just recommend these settings.

Tagged with: , , , , ,
Posted in Grails, Groovy, IntelliJ, Java, Webserver
One comment on “Grails: java.lang.OutOfMemoryError: PermGen space
  1. This is awesome full blog I like this sort blog. Your work is truly awesome and excessively valuable. I delighted in going to your site. You have made a really great Showing with regards to. Visit my website and get quality service at least cost.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Anti-spam protection

Prove that you are Human by typing the emphasized characters:


Protected by Gab Captcha 2

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>