Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear PermGen space Error in tomcat

I am working in a Windows Environment, and I am getting this error every time I am working with tomcat-

Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet default threw exception java.lang.OutOfMemoryError: PermGen space 2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@4ae53a99 2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} java.net.ConnectException: Connection refused: no further information Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet default threw exception java.lang.OutOfMemoryError: PermGen space Exception in thread "Memcached IO over {MemcachedConnection to localhost/127.0.0.1:11211}" java.lang.OutOfMemoryError: PermGen space Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process SEVERE: Error processing request java.lang.OutOfMemoryError: PermGen space Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process SEVERE: Error processing request java.lang.OutOfMemoryError: PermGen space Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process SEVERE: Error processing request java.lang.OutOfMemoryError: PermGen space Apr 30, 2012 5:30:41 PM org.apache.catalina.connector.CoyoteAdapter service SEVERE: An exception or error occurred in the container during the request processing java.lang.OutOfMemoryError: PermGen space Apr 30, 2012 5:30:43 PM org.apache.catalina.core.StandardHostValve custom SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error.action] java.lang.OutOfMemoryError: PermGen space Apr 30, 2012 5:30:42 PM org.apache.catalina.core.StandardHostValve custom SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error.action] java.lang.OutOfMemoryError: PermGen space Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space 

I tried adding JAVA_OPTS with the value as -Xms1024m -Xmx1024m in System Variables, but I am stillgetting the same error (java.lang.OutOfMemoryError: PermGen space) again and again.

Any help will be appreciated. I have also read other posts on Stack Overflow also but it didn't work out.

like image 709
AKIWEB Avatar asked May 01 '12 00:05

AKIWEB


People also ask

How do you fix a PermGen error?

To fix it, increase the PermGen memory settings by using the following Java VM options. -XX:PermSize<size> - Set initial PermGen Size. -XX:MaxPermSize<size> - Set the maximum PermGen Size. In the next step, we will show you how to set the VM options in Tomcat, under Windows and Linux environment.

What causes PermGen space error?

lang. OutOfMemoryError: PermGen Space is a runtime error in Java which occurs when the permanent generation (PermGen) area in memory is exhausted. The PermGen area of the Java heap is used to store metadata such as class declarations, methods and object arrays.

How can I increase my PermGen size?

To increase the PermGen memory change the value of the MaxPermSize variable, otherwise change the value of the Xmx variable. There are a lot of answers similar to this around but I found that this was the clearest and simplest phrased, very helpful.


1 Answers

The PermGen space is what Tomcat uses to store class definitions (definitions only, no instantiations) and string pools that have been interned. From experience, the PermGen space issues tend to happen frequently in dev environments really since Tomcat has to load new classes every time it deploys a WAR or does a jspc (when you edit a jsp file). Personally, I tend to deploy and redeploy wars a lot when I’m in dev testing so I know I’m bound to run out sooner or later (primarily because Java’s GC cycles are still kinda crap so if you redeploy your wars quickly and frequently enough, the space fills up faster than they can manage).

This should theoretically be less of an issue in production environments since you (hopefully) don’t change the codebase on a 10 minute basis. If it still occurs, that just means your codebase (and corresponding library dependencies) are too large for the default memory allocation and you’ll just need to mess around with stack and heap allocation. I think the standards are stuff like:

-XX:MaxPermSize=SIZE 

I’ve found however the best way to take care of that for good is to allow classes to be unloaded so your PermGen never runs out:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled 

Stuff like that worked magic for me in the past. One thing tho, there’s a significant performance tradeoff in using those, since permgen sweeps will make like an extra 2 requests for every request you make or something along those lines. You’ll need to balance your use with the tradeoffs.

like image 108
Michael Avatar answered Sep 22 '22 08:09

Michael