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:
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
About the author
Hi, my name is Artur Ejsmont,
welcome to my blog. I am a passionate software engineer living in Sydney and working for Yahoo!
If you are into technology, you can order my book Web Scalability for Startup Engineers on Amazon. I would love to hear what are your thoughts so please feel free to drop me a line or leave a comment.