45

i get this exception frequently when running my app on tomcat using eclipse:

java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1850)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1850)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:265)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
    at com.spacerdv.dao.impl.UserDaoImpl.getUserDetails(UserDaoImpl.java:170)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
  • possible duplicate of [How to deal with "java.lang.OutOfMemoryError: PermGen space" error](http://stackoverflow.com/questions/88235/how-to-deal-with-java-lang-outofmemoryerror-permgen-space-error) – Lucero Jul 05 '10 at 11:41

3 Answers3

97

try to raise perm space, add following parameters to vm start-up

-XX:PermSize=256m -XX:MaxPermSize=256m

also add -XX:MaxPermSize=256m to Tomcat in Eclipse: Server > Open Launch Configuration > Arguments

Update (in 2014): take a look here at this question and answer about the new Java 8 Metaspace.

and take a look here:

How to deal with “java.lang.OutOfMemoryError: PermGen space” error

Community
  • 1
  • 1
Chris
  • 15,429
  • 19
  • 72
  • 74
  • On Netbeans this parameters can be added in: Services > Servers > Apache Tomcat (right click) > Properties > Platform > VM Options – DragonT Mar 10 '15 at 20:20
  • also you might wanna add `-server -Xmx1024m` – QuakeCore Oct 19 '15 at 08:42
  • 1
    This solution only postpones the problem. My tomcat usually runs at MaxPermSize=512m and still exhausts the PermSize. It happens when changed code gets autodeployed too often. My workaround is to restart tomcat explicitly every once in a while. – Hok May 31 '16 at 11:53
21

You can configure these arguments for eclipse:

"To solve this I stopped the server in Eclipse. Double clicked on the server in the Servers tab to open the Overview page for the server. Clicked on Open Launch Configuration and then on the Arguments tab.

I added the following VM arguments :

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

ref to http://malcolmmallia.com/malcblog/?p=60

Anil Bharadia
  • 2,760
  • 6
  • 34
  • 46
Ali
  • 301
  • 3
  • 4
  • Thank you! Our team was having some issues on our QA and production servers after changing web service stacks, and these two options fixed our PermGen issues. (For now at least.) – The Awnry Bear Apr 03 '12 at 17:42
5

I got this problem today as well. It happened completely out of the blue. Yesterday I've updated JDK/JRE from 1.6.0_13 to 1.6.0_21 to fix a Glassfish 3.0.1 specific issue and Eclipse suddenly broke with those OutOfMemoryError: PermGen space errors. After (incorrectly) ranting on the Glassfish plugin and concluding that the issue wasn't fixed after cleaning the workspace metadata, it turns out that this is caused by the change of JVM vendor string from "Sun" to "Oracle" since 1.6.0_20. Eclipse didn't recognize the new JVM vendor and thus didn't apply the VM arguments as specified in eclipse.ini.

This was reported as Eclipse issue 319514 and the Eclipse boys quickly released a patch. Until they get it fixed more permanently, the workaround is indeed to add the following lines to the eclipse.ini:

-XX:MaxPermSize=256m

So, if you recently did a JVM update, it might be worth to take a look to it.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555