Jetty 7: OutOfMemoryError: PermGen space on application redeploy
Asked Answered
H

6

5

First time app starts correctly. Then I delete webapp/*.war file and paste new version of *.war. Jetty start deploying new war but error java.lang.OutOfMemoryError: PermGen space occurs. How can I configure Jetty to fix error / make correct redeploy?

This solution doesn't help me.
Jetty version: jetty-7.4.3.v20110701

Hendrika answered 5/8, 2011 at 12:54 Comment(0)
S
11

There is probably no way to configure the problem away. Each JVM has one PermGen memory area that is used for class loading and static data. Whenever your application gets undeployed its classloader should be discarded and all classes loaded by it as well. When this fails because other references to the classloader still exist, garbage collecting the classloader and your applications classes will also fail.

A blog entry and its follow up explain a possible source of the problem. Whenever the application container's code uses a class that holds a reference to one of your classes, garbage collection of your classes is prevented. The example from the mentioned blog entry is the java.util.logging.Level constructor:

protected Level(String name, int value) {
    this.name = name;
    this.value = value;
    synchronized (Level.class) {
        known.add(this);
    }
}

Note that known is a static member of java.util.logging.Level. The constructor stores a reference to all created instances. So as soon as the Level class was loaded or instantiated from outwith your application's code, garbage collection can't remove your classes.

To solve the problem you could avoid all classes that are in use outwith your own code or ensure no references are held to your classes from outwith your code. Both problems could occur within any class delivered with Java and are thus not feasible to be fixed within your application. You cannot prevent the problem by altering only your own code!

Your options are basically:

  • Increasing the memory limits and have the error strike less often
  • Analyze your code as detailed in the linked blog posts and avoid using the classes that store references to your objects
Swarey answered 17/9, 2011 at 21:32 Comment(3)
Any guidelines as to how to go about detecting the culprit classes?Bracketing
I'm sorry, I don't have simple steps to follow. You can try an ordinary heap dump and examine it for unexpected objects. The references to them might give you enough clue to spot the leak. You might also find a useful tool for the search in Eclipse's Memory Analyzer: eclipse.org/matSwarey
Answer was edited because blogs.oracle.com/fkieviet/entry/… was moved to frankkieviet.blogspot.hu/2006/10/… and blogs.oracle.com/fkieviet/entry/how_to_fix_the_dreaded was moved to frankkieviet.blogspot.hu/2006/10/… Thanks for noting, @sasfalvi-tamásSwarey
B
7

If a PermGen out of memory occurs, you need to restart the jvm, in your case restart jetty. You may increase the PermGen space with the JVM options in your linked solution so this happens later (with later I mean: after more redeploys). But it will happen every once in a while and you can do next to nothing to avoid that. The answer you linked explained well what PermGenSpace is and why it overflows.

Use:

-XX:PermSize=64M -XX:MaxPermSize=128M

or, if that was not enough yet

-XX:PermSize=256M -XX:MaxPermSize=512M

Also, be sure to increase the amount of space available to the vm in general if you use this commands.

use

-Xms128M -Xmx256M
Ballistic answered 15/9, 2011 at 12:17 Comment(0)
A
1

For Jetty 7.6.6 or later this may help http://www.eclipse.org/jetty/documentation/current/preventing-memory-leaks.html.

We used the AppContextLeakPreventer and it helped with the OOM errors due to permgen space

Authoritative answered 17/10, 2014 at 14:9 Comment(0)
P
0

I have this same problem with HotSpot, but with JRockit, which doesn't have a Permanent Generation, the problem has gone away. It's free now, so you might want to try it: https://blogs.oracle.com/henrik/entry/jrockit_is_now_free_and

Ptyalin answered 17/2, 2012 at 14:42 Comment(0)
F
0

Looks very much like Permanent Generation leak. Whenever your application left some classes to hang around after it is undeployed, you get this problem. You can try the latest version of Plumbr, may be it will find the left-over classes.

Farnsworth answered 17/7, 2012 at 9:4 Comment(0)
B
0

For Readers of the Future (relative to when this question has been asked):

In JDK 8 the Perm Gen Space is gone (not there anymore). Instead there is now Metaspace which is taken from the native space of the machine.

If you had problems of Perm Gen Overflow then you might want to have a look into this explanation and this comments on the removal process.

Ballistic answered 13/3, 2014 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.