Fixing java.lang.OutOfMemoryError: PermGen Out of Memory in grails STS and tomcat

Grails, Tomac and Glassfish keep on crashing during deployment or reloading of your web application with out of memory permgen space errors? Seems like you are one of the millions other developers that have this problem : -)

Its all about loading too many classes. In Java classes are loaded in special memory area which can not grow above the max perm gen setting.

It may be frustrating especially if you are at the beginning of your journey with grails. Grails spring, hibernate and all the plugins depend on so many jars and classes that default memory settings are often not enough.

How to fix tomcat java.lang.OutOfMemoryError: PermGen Out of Memory

To fix the problem edit your tomcat startup script and add the following to set the JVM options:

export JAVA_OPTS="-XX:MaxPermSize=512m"

Just add it at the top of the file just below #!bin/sh

How to fix java.lang.OutOfMemoryError: PermGen Out of Memory in grails commands

You may have the same problem while running grails commands for example run-app. Grails commands use java JVM as well and it also needs max perm gen space set properly. With grails it is a bit different story. to make it work its best to set environment variable in your bash profile file or other system login script. You can also edit grails start script.

Add this to your .bash_profie or whatever is ran every time you login to your mac/linux:

export GRAILS_OPTS="-server -Xmx512M -XX:MaxPermSize=512m -Dfile.encoding=UTF-8"

How to fix java.lang.OutOfMemoryError: PermGen Out of Memory in STS or other IDE ran container

You will have to add the same directive to JVM options in your tomcat executing command or in general in your JVM / JDK definition.

If you have doubts what options are used run

ps aux | grep java | less

It should show you what is the command that is ran by IDE and what are the options passed. Keep on digging in IDE configuration menus till you find the correct java options field :P

hope it helps

Comments

Actually for certain cases,

Actually for certain cases, the VMWare tc Server is the one running out of memory because STS runs a another instance of the JVM for it. To fix, edit the run configuration for the tc Server and set -XX:MaxPermSize=512m from the Arguments tab.

Hope this helps.

N.

2012-09-26 22:56
Anonymous

Thank you very much for this

Thank you very much for this post. I have been struggling with grails for DAYS (starting with the installation of STS). My problem started when calling grails command in the console, and after exiting, the console cursor and anything I typed was invisible.

Then, after calling grails, nothing happened (no error messages, nothing, just returned to the prompt). I started to suspect problems with java, and that's why I ended up here.

So, it was all a memory problem. Amazing.

Thanks a lot again!

2012-05-24 23:03
Jeudy

It depends how do you run

It depends how do you run your container, try to grep the files for JAVA_OPTS if i remember right it was a bash script that was used to start tomcat up

export is a bash command used to set shell environment variables and JVM uses some of them. If you start tomcat as java ... jar then just execute this export beforehand to make sure this environment variable is set.

Art

2012-03-14 01:37
admin

Thanks for the post ... I am

Thanks for the post ...
I am getting the problem in TomCat.. It's getting Out Of memory permgen space
I got an Idea after going through your code , But i have one doubt where i have to paste this code..

export JAVA_OPTS="-XX:MaxPermSize=512m"

Could you please Explain me how to and where i have to paste this code.

Thanks Regards
Ashraf Shaida

2012-03-13 06:37
Ashraf Shaida

People often don't

People often don't differentiate between OOOM in Heap and OOOM in Perm Gen, even though both are completely different and require different approach to solve. I come to know when I got this error on tomcat and see 2 ways to solve java.lang.OutOfMemoryError:Perm Gen Space in Java article, quite useful for me.

2011-11-16 17:24
Rajiv

Post new comment

Image CAPTCHA

About the author

Artur Ejsmont

Hi, my name is Artur Ejsmont,
welcome to my blog.

I am a passionate software engineer living in Sydney and working for Yahoo! Drop me a line or leave a comment.

Follow my RSS