Java 中heap leak是最常见的memory leak。OutOfMemoryError 是其最常见的征兆。 Memory leak有以下几种情况
- java.lang.OutOfMemoryError: Java heap space
- java.lang.OutOfMemoryError: PermGen space
- java.lang.OutOfMemoryError: array size exceeds VM limit
- java.lang.OutOfMemoryError: request bytes for . Out of swap space?
- java.lang.OutOfMemoryError: (Native method)
具体介绍前两种
1. Java heap space
也有不同的可能性。
a. 特别是对于长时间存活long-lived applications, 如果有一些长期被referenced objects,GC无法释放内存
b. finalizers。如果一个类定义了finalize函数,那么这个对象的空间不会被GC释放,相反他们are queued for finalization,是在GC清理之后才会执行。
2. Permgen space
"Permanant generation" 是用来存放loaded 类的class declarations,包括类名,类的fields,类的函数等等。因此它得大小depend on 被加载的类的数量以及这些类declaration的大小。
a. 例如写一个程序不停的generate不同的类,会造成溢出。
b. 另外一种常见的造成溢出的原因是一些第三方的lib。在程序redploy的时候,旧的classloader referencing all the previously loaded classes会被新classloader取代,但是有些第三方lib的poor handling of resources导致这些旧的classes仍然存在,导致溢出。
c. Interned java.lang.String objects也是存放在permgen里的。
解决方案:configuration里增加permgen的容量,或者利用类似plumbr的工具找到问题所在。
Read full article from memory leak | codesolutiony
No comments:
Post a Comment