标签:perm tag faq tab help mat method ecif and
That is because your web application has a memory leak.
A common issue are "PermGen" memory leaks. They happen because the Classloader (and the Class objects it loaded) cannot be recycled
unless some requirements are met (*). They are stored in the permanent heap generation by the JVM, and when you redeploy a new class
loader is created, which loads another copy of all these classes. This can cause OufOfMemoryErrors eventually.
(*) The requirement is that all classes loaded by this classloader should be able to be gc‘ed at the same time.
To avoid memory leaks, you need to pay attention to how you write your code. Here are specific methods to help you stamp out memory leaks.
Using the java.lang.ref package, you can work with the garbage collector in your program. This allows you to avoid directly referencing objects,
but use special reference objects that are easily cleared by the garbage collector. The special subclasses allow you to refer to objects indirectly.
For instance, Reference has three subclasses: PhantomReference, SoftReference, and WeakReference.
A referent, or an object that is referenced by these subclasses, can be accessed using that reference object’s get method. The advantage of
using this method is that you can clear a reference easily by setting it to null and that the reference is pretty much immutable, or it cannot be
changed. How does garbage collector act with each type of referent?
Using reference objects, you can work with the garbage collector to automate the task of removing listeners that are weakly reachable.
WeakReference objects, especially with a cleanup thread, can help you avoid memory errors.
If you are using Jetty 7.6.6. or higher, you can prevent WebApp classloader pinning. When your code keeps referring to a webapp classloader,
memory leaks can easily happen. There are two types of leaks in this case: daemon threads and static fields.
出处:
tomcat wiki:
Why does the memory usage increase when I redeploy a web application?
Different types of leaks that Tomcat can detect
其他博客:
What to Do About Java Memory Leaks: Tools, Fixes, and More
Why does the memory usage increase when I redeploy a web application?
标签:perm tag faq tab help mat method ecif and
原文地址:http://www.cnblogs.com/yuyutianxia/p/7746849.html