Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PermGen Out of Memory reasons

I constantly detect OOM in PermGen for my environment:

  1. java 6
  2. jboss-4.2.3
  3. Not a big web-application

I know about String.intern() problem - but I don't have enough valuable usage of it. Increasing of MaxPermGen size didn't take a force (from 128 Mb to 256 Mb).

What other reasons could invoke OOM for PermGen? What scenario of investigation is the best in such situation (strategy, tools and etc.)?

Thanks for any help

like image 671
Raman Avatar asked Apr 12 '11 12:04

Raman


People also ask

What is the exact reason of replacing PermGen memory with MetaSpace in java8?

In Java 8, PermGen method area replaced with MetaSpace. They have moved permGem to the separate memory in the native OS and that is called MetaSpace. It can by default auto increases its size. In MetaSpace, classes can load and unload during the lifespan of the JVM.

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 is the PermGen section in memory?

PermGen (Permanent Generation) is a special heap space separated from the main memory heap. The JVM keeps track of loaded class metadata in the PermGen. Additionally, the JVM stores all the static content in this memory section.

How do I fix I have out of memory exception?

1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.


2 Answers

See this note

  • Put JDBC driver in common/lib (as tomcat documentation says) and not in WEB-INF/lib
  • Don't put commons-logging into WEB-INF/lib since tomcat already bootstraps it

new class objects get placed into the PermGen and thus occupy an ever increasing amount of space. Regardless of how large you make the PermGen space, it will inevitably top out after enough deployments. What you need to do is take measures to flush the PermGen so that you can stabilize its size. There are two JVM flags which handle this cleaning:

-XX:+CMSPermGenSweepingEnabled

This setting includes the PermGen in a garbage collection run. By default, the PermGen space is never included in garbage collection (and thus grows without bounds).

-XX:+CMSClassUnloadingEnabled

This setting tells the PermGen garbage collection sweep to take action on class objects. By default, class objects get an exemption, even when the PermGen space is being visited during a garabage collection.

like image 142
Dead Programmer Avatar answered Sep 18 '22 13:09

Dead Programmer


You typically get this error when redeploying an application while having a classloader leak, because it means all your classes are loaded again while the old versions stay around.

There are two solutions:

  • Restart the app server instead of redeploying the application - easy, but annoying
  • Investigate and fix the leak using a profiler. Unfortunately, classloader leaks can be very hard to pinpoint.
like image 35
Michael Borgwardt Avatar answered Sep 20 '22 13:09

Michael Borgwardt