4

我一直在我的电脑上本地测试我的 webapp 并使用 VisualVM 监控它。我最近也开始使用 JMeter,因为有人建议我应该做一些负载测试,因为我怀疑我在某处有缓慢的内存泄漏。

今天我的 webapp 终于抛出了OutOfMemory异常。我设置了HeapDumpOnOutOfMemoryErrorandHeapDumpPath参数以防万一发生这种情况。生成了一个堆转储文件。

我在 VisualVM 中打开了这个文件(java_pid2760.hprof),老实说,我不明白我应该如何查明这个内存泄漏的罪魁祸首......

如何使用 VisualVM 分析堆转储并找到产生内存泄漏的类/实例?

4

2 回答 2

3

Here's a couple of links I found helpful when debugging memory leaks:

http://olex.openlogic.com/wazi/2009/how-to-fix-memory-leaks-in-java/

http://www.ibm.com/developerworks/rational/library/05/0816_GuptaPalanki/

Edit:

You might also want to try: http://rejeev.blogspot.com/2009/04/analyzing-memory-leak-in-java.html

于 2011-02-07T18:01:58.073 回答
1

Using VisualVM to analyze heap dumps and pin-point memory leaks is not easy, and I wouldn't recommend using this tool if this is your first time working on this type of problem. Consider downloading HPjmeter and letting it do the work for you.

After opening the dump file, select the Sorted Reference Graph Subtree option. This will show you all of the objects in your webapp sorted by size. In most memory leak scenarios, you are leaking one type of Object that balloons over time in the heap. HPjmeter will help you identify this case quickly.

于 2011-02-07T18:01:21.130 回答