I am seeing 'java.lang.OutOfMemoryError: PermGen space' while running ~300 JUnit tests and using Spring context. Having a tough time figuring out what's eating up PermGen since:
-XX:+TraceClassLoading
and -XX:+TraceClassUnloading
enabled, I see no additional "loading" events while executing the last 20-30 tests before the OutOfMemoryError
.The latter seemingly suggests that something besides Class objects is filling PermGen, no? If so, what could it be? For example, are there circumstances when class instances are stored in PermGen?
Here's my VM info:
$ java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
related
FWIW, the root of my problem that precipitated this post turned out to be somewhat trivial: I assumed that Maven Surefire plugin inherits VM settings from MAVEN_OPTS (or VM instance running mvn) when it forks a VM - it does not (boo). One has to specify those explicitly using argLine in plugin's configuration. HTH.
The PermGen area of the Java heap is used to store metadata such as class declarations, methods and object arrays. Therefore, the PermGen size requirements depend on the number of classes and methods as well as their size. Java memory is separated into different regions - Young, Tenured and PermGen.
The PermGen is garbage collected like the other parts of the heap. The thing to note here is that the PermGen contains meta-data of the classes and the objects i.e. pointers into the rest of the heap where the objects are allocated.
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.
Open eclipse. ini file, it is located in root eclipse directory. there you can change -Xms and -Xmx parameter to change permgen size. There you can change -XX:PermSize and -XX:MaxPermSize.
Sometimes abuse of String.intern() can cause out of PermGen space errors since interned String instances are stored in PermGen.
This might be what you are seeing - try eliminating unnecessary String.intern() calls to see if this solves the problem. In general, I wouldn't recommend using String.intern() unless you are sure that both of the following are true:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With