3
votes

I have application with settings: -Xmx2048M, -Xms2048M, -XX:MaxPermSize=256M.
Sometimes I get a lot of messages in log:

[Unloading class sun.reflect.GeneratedMethodAccessor9]  
[Unloading class sun.reflect.GeneratedMethodAccessor129]  
[Unloading class sun.reflect.GeneratedMethodAccessor12]  
[Unloading class sun.reflect.GeneratedMethodAccessor11]  
[Unloading class sun.reflect.GeneratedMethodAccessor12]  
[Unloading class sun.reflect.GeneratedMethodAccessor11]  
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor29]  
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor25]  

and get error:

OutOfMemoryError: Java heap space

After reading this article:
http://anshuiitk.blogspot.com/2010/11/excessive-full-garbage-collection.html
I know, that classes are load in Perm Gen and should occur error:

OutOfMemoryError: PermGen space.

My question, why I have error OutOfMemoryError: Java heap space instead of
OutOfMemoryError: PermGen space?

2

2 Answers

2
votes

This means you are running out of heap space (or you have a space which cannot grow for some reason)

You only get PermGen space. as a reason when the maximum for this space runs out.

In short, you are getting this error because your heap space cannot grow to hold the objects in it.

1
votes

Like @Peter tells it's a heap issue. Unloading is a side effect of the full garbage collection, not an indication of anything going amiss.

Here is how to resolve and prevent OOMs:

  • Allow heap dumps on OOM -XX:+HeapDumpOnOutOfMemoryError on hotspot, the option has no performance penalties
  • Study the heap dump and understand where you have a leak or overcommitted use of heap, e.g. huge selects from a database.
  • Once you get proficient at heap analysis, take heap dumps via jmap during development and analyze for leaks.
  • If you believe you may have leaks in production: jmap -histo is a good option as it enjoys little performance hit only.