Java.lang.OutOfMemoryError: PermGen space

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Troubleshooting]]
 
[[Category:Troubleshooting]]
  
This error occurs when the JVM runs out of space in the permanent generation heap.
+
This error occurs when the JVM runs out of space in the permanent generation heap. Since the defaults for the JVM are quite low, the first step should be to increase the default using [[-XX:MaxPermSize]].
  
If the application(s) in the server use a large number of classes, the solution is
+
  <!-- verbose garbage collection -->
to increase the value specified with [[-XX:MaxPermSize]]. 
+
  <jvm-arg>-XX:MaxPermSize=256m</jvm-arg> <!-- sets the maximum size of the permanent heap (recommended) -->
  
If the error occurs only after the redeployment and restart of new applications, then the likely  
+
 
 +
If the default has been increased and error occurs only after the redeployment and restart of new applications, then the likely  
 
cause is that the JVM cannot garbage collect old classes that are replaced because there are  
 
cause is that the JVM cannot garbage collect old classes that are replaced because there are  
 
references to the old classes, as discussed in [[Classloader references]].
 
references to the old classes, as discussed in [[Classloader references]].
Line 23: Line 24:
 
     // we revert back to Merlin (1.4.0) behavior and only save this             
 
     // we revert back to Merlin (1.4.0) behavior and only save this             
 
     // information if an agent is currently attached.
 
     // information if an agent is currently attached.
 +
 +
== See Also ==
 +
 +
; [[OutOfMemoryError]]

Latest revision as of 19:49, 8 April 2008


This error occurs when the JVM runs out of space in the permanent generation heap. Since the defaults for the JVM are quite low, the first step should be to increase the default using -XX:MaxPermSize.

 <!-- verbose garbage collection -->
 <jvm-arg>-XX:MaxPermSize=256m</jvm-arg> <!-- sets the maximum size of the permanent heap (recommended) -->


If the default has been increased and error occurs only after the redeployment and restart of new applications, then the likely cause is that the JVM cannot garbage collect old classes that are replaced because there are references to the old classes, as discussed in Classloader references.

MaxPermSize and debuggers (agents)

The JDK's permanent memory behaves differently depending on whether a debugging is enable, i.e. if there is an active agent.

If there is an active agent, the JDK can fail to collect permanent memory in some cases. (Specifically, when some code introspects a class with a primitive array like, byte[] or char[].) This can cause the permanent space to run out, for example, when redeploying .war files.

From the JDK source code (systemDictionary.cpp):

   // Update: if a Java program cycles through a lot of class loaders          
   // and the classes loaded by those class loaders have a lot of              
   // primitive arrays, then the perm gen explodes in size. For now,           
   // we revert back to Merlin (1.4.0) behavior and only save this             
   // information if an agent is currently attached.

See Also

OutOfMemoryError
Personal tools