Why is PermGen space growing?

2020-05-16 03:28发布

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:

  • Young Generation: objects that are created go here, this part is frequently and inexpensively garbage collected

  • Old Generation: objects that survive the garbage collections of the Young generation go here, this area is garbage collected less frequently and using a more CPU demanding process/algorithm (I believe it's called mark-sweep)

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

  • PermGen: this area is filled of your app classes metadata and many other things that do not depend on the application usage.

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?

7条回答
看我几分像从前
2楼-- · 2020-05-16 03:50

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

查看更多
孤傲高冷的网名
3楼-- · 2020-05-16 03:52

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

查看更多
别忘想泡老子
4楼-- · 2020-05-16 04:03

The most common causes I've seen are:

  1. Java classes are loaded
  2. JAXBContext.newInstance
  3. String.intern()
查看更多
Root(大扎)
5楼-- · 2020-05-16 04:05

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

查看更多
家丑人穷心不美
6楼-- · 2020-05-16 04:10

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.
查看更多
爱情/是我丢掉的垃圾
7楼-- · 2020-05-16 04:10

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.
查看更多
登录 后发表回答