2009年2月20日星期五

JDev_013:使用JDeveloper 11g 检查内存泄漏

使用 Run->Memory Profiler 可以帮助我们查看程序是如何使用Java Heap的,从而确定是否有内存泄漏。

1. Classes 视图
排序显示所有对象垃圾回收前后的所占内存大小。

2. Allocators 视图
按调用层次显示所有方法占用的内存大小。


3. 参数说明
(1)%:
The title of this column varies depending on which numeric column is selected.
For example, if the New column is selected, the title will be New %.
The column shows the percentage of the total of the selected column in the current row.
A bar graph (histogram) is drawn to the left of the numeric percentage.

(2)New:新创建的对象实例数
For a class, the number of objects of this class created in this use case.
For a method, the number of objects of this class created by this method or any methods it calls.

(3)Newx:
Applicable to methods only.
Displays the number of class objects created by this method.

(4)New Size:新创建的对象实例数所占的内存大小
For a class, displays the number of bytes used by newly created objects of the class.
For a method, displays the number of bytes used by objects of the class created by this method or any methods it calls.

(5)New Sizex:
Applicable to methods only. Displays the number of bytes used by class objects created by this method only.

(6)GC:被回收的对象实例数
Applicable to classes only. Displays the number of objects of this class garbage collected in the current use case.

(7)GC Size:被回收的对象实例数所占的内存大小
Applicable to classes only. Displays the number of bytes in objects of the class freed up by garbage collection.

(8)Initial Num:测试开始时的对象实例数
Applicable to classes only. Displays the number of objects of this class that existed when the current use case began.

(9)Initial Size:测试开始时的对象实例数所占的内存大小
Applicable to classes only. Displays the number of bytes used by objects of this class when the current use case began.

(10)Final Num:测试结束时的对象实例数
Applicable to classes only. Displays the number of objects of this class that exist currently for an active use case, or at the end of the use case.

(11)Final Size:测试结束时的对象实例数所占的内存大小
Applicable to classes only. The number of bytes used by objects of this class currently (for an active use case) or at the end of the use case.

(12)New-GC:新创建的对象经过GC后还剩的实例数
Applicable to classes only. Displays the number of newly created objects of this class that remain in the memory.
In other words, objects that were created by new but not garbage collected are reported.
At the end of a use case, this number may indicate a memory leak in the use case.

(13)New-GC Size:新创建的对象经过GC后还剩的实例数所占的内存大小
Applicable to classes only.
Displays the number of bytes used by newly created objects of this class that were not garbage collected.

4. 典型案例
listeners.add(new WeakReference(listener));

没有评论: