OutOfMemoryError and Unloading class sun.reflect.GeneratedMethodAccessor
Solution 1
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.
Solution 2
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.
luk4443
Updated on July 26, 2022Comments
-
luk4443 almost 2 years
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? -
luk4443 about 12 yearsThanks for response. But this messages [Unloading class sun.reflect.GeneratedMethodAccessor9] indicates problem in Perm Gen and why I don't get OutOfMemoryError: PermGen space, or maybe first OutOfMemoryError: PermGen and then next OutOfMemoryError: Java heap space?
-
Vishy about 12 yearsThe message indicates the PermGen was cleaned up. No more than that. You will always get a Full GC before an
OOME Java heap space
and that will clean up all areas including the perm gen (even if there is plenty of space there) -
luk4443 about 12 yearsSo far I thought, that this OutOfMemoryError is trigger by soft references when GC cannot properly clean it. But it seems, there are another reason of OOME?
-
Vishy about 12 yearsSoft references can change your GC behaviour, but won't trigger an OMEE unless you have many millions of them.
-
luk4443 about 12 yearsThanks. I have several hundred messages like Unloading class sun.reflect.GeneratedMethodAccessor. Heap spase rises to about 1,8 G and trigger an OOEM. So there are very intensive object creating or just memory leaks?
-
Vishy about 12 yearsIf you are using lots of reflection in your libraries you can get lots of these messages. I have been working on 64-bit JVMs for a few years and I start with a heap of 8 GB and increase or decrease it as required. 1.8 GB doesn't sound like too much unless you have a 32-bit machine.
-
luk4443 about 12 yearsA lot of time I spend to find cause of trigger an OOEM Java heap space. It is triggered when heap space grow to about 1,8 G (-Xmx2048M). But twice there are another situation - heap grow to maximum (several MB free), but there aren't OOEM Java heap space. But application server restarted. Maybe could you aim me to reason of this problems?
-
Vishy about 12 yearsWhat do you mean
application server restarted
? -
luk4443 about 12 yearsAfter about hour of application running with 95% heap space use, application server itself restarted.But when occurs an OOEM, situation last about 15 min. before an OOEM: Java heap space (but server doesn't restart itself).
-
Cameron over 11 yearsIt's no secret he has run out of heap space, that's in the error message. But the question is how are these messages related to garbage collection and memory issues? I see these messages often in GC logs before long GC pauses, not out of memory errors. But it's not clear to me what these messages are indicative of and how I can reduce their negative consequences.
-
Vishy over 11 yearsThe best thing to do is to use a memory profiler to minimize object creation and usage. Once you have done this you can look at how the GC logs compare with the graphs you see in VisualVM.