Pablo Fernandez
Pablo Fernandez

Reputation: 105220

Why is PermGen space growing?

I've read a few articles, and I understood the following (please correct me and/or edit the question if I'm wrong):

The java heap is segmented like this:

Edit: as stated by another user, PermGen is not a part of the region called heap

So, knowing this... why does my PermGen space grows when the app is under heavy load? For what I said before this space should not incrementally fill in spite of the app load, but as I said in the beginning probably I'm wrong about some assumptions.

In fact if the PermGen space is growing, is there a way of garbage collect or reset it?

Upvotes: 17

Views: 25751

Answers (7)

Jim Mitchener
Jim Mitchener

Reputation: 9003

This is a very common problem when you are manipulating the classloader. This is seen a lot in Java EE apps when you are redeploying hibernate/cglib. For more info check out

http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go

Upvotes: 0

stones333
stones333

Reputation: 8958

The most common causes I've seen are:

  1. Java classes are loaded
  2. JAXBContext.newInstance
  3. String.intern()

Upvotes: 0

Sajid
Sajid

Reputation: 79

If you are working with Java EE application it's probably a classloader leak.

you might find the following additional links to be useful:

http://www.zeroturnaround.com/blog/rjc201/

http://www.ibm.com/developerworks/java/library/j-dclp3/index.html

Upvotes: 2

Jason Stelzer
Jason Stelzer

Reputation: 161

This is one of the more annoying problems to debug. There are a lot of reasons you could be seeing growing permgen use. Here are 2 links I found very useful in both understanding how leaks happen as well as tracking down what is causing them.

http://frankkieviet.blogspot.com/2006/10/how-to-fix-dreaded-permgen-space.html

http://frankkieviet.blogspot.com/2006/10/classloader-leaks-dreaded-permgen-space.html

Upvotes: 6

Joshua McKinnon
Joshua McKinnon

Reputation: 24709

Actually, in Sun's JVM Permanent Generation (PermGen) is completely separate from the heap. Are you sure you aren't looking at the Tenured Generation? It would be suspicious indeed if your Permanent Generation kept growing.

If your perm gen IS growing constantly, it is a difficult area to dig into. Generally it should grow when new classes are loaded for the first time (and potentially certain uses of reflection could also cause this). Interned strings are also stored in perm gen.

If you happen to be on Solaris, you could use jmap -permstat to dump out perm gen statistics, but that option does not appear to be available on Windows (and potentially other platforms). Here is the documentation on jmap for Java 6

From Sun's guide on JConsole (which will let you view the size of these pools):

For the HotSpot Java VM, the memory pools for serial garbage collection are the following.

  • Eden Space (heap): The pool from which memory is initially allocated for most objects.
  • Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.
  • Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.
  • Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
  • Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.

Upvotes: 19

John Stauffer
John Stauffer

Reputation: 16360

The most common causes I've seen are:

  • Custom classloaders that don't carefully free up older classes after loading new ones.
  • Classes remaining in PermGen after redeploying an application multiple times (more common in Dev than Prod)
  • Heavy use of Proxy classes, which are created synthetically during runtime. It's easy to create new Proxy classes when an a single class definition could be reused for multiple instances.

Upvotes: 6

Jonathan Feinberg
Jonathan Feinberg

Reputation: 45324

Are you doing something funky with the classloader chain? Are you calling intern() on a bunch of strings?

Upvotes: 2

Related Questions