Java内存泄漏 [英] Java memory leak

查看:116
本文介绍了Java内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人使用Eclipse内存管理器来检测java代码中的内存泄漏?任何人都可以推荐一个好地方来寻找有关使用内存管理器的信息?我在线阅读,这表明我需要让程序运行,直到它崩溃(内存不足错误发生),这将生成崩溃报告。然后使用内存管理器打开此报告来检查内存泄漏可能发生的位置。这是每个人都使用内存管理员吗?

解决方案

虽然 - XX:+ HeapDumpOnOutOfMemoryError 可以很有用,我目前使用Eclipse内存管理器的工作流程是: p>


  1. 正常运行程序

  2. 等待内存失控。

  3. 运行 jmap jmap -dump:format = b,file = dump.hprof< PID>

  4. 打开EMM中的hprof文件。 li>

我通常开始使用直方图和支配树视图来查看是否有任何东西似乎没有了,然后从那里向下钻取。 >

使用堆转储时,VisualVM可能很有用,但效率远低于EMM(EMM缓存了大量有关加载堆转储的信息)。 Netbeans Profiler非常适合获取分配位置和时间分析。


Has anybody used Eclipse memory manager to detect memory leak in java codes? Can anybody recommend a good place to look for information regarding using memory manager? I read something online, it suggests that i need to let the program run until it crashes (out of memory error occurs), which will generates a crash report. Then use the memory manager to open this report to examine where the memory leak might occur. Is this how everybody uses memory manager?

解决方案

Though -XX:+HeapDumpOnOutOfMemoryError can be useful, my current workflow for using the Eclipse Memory Manager is:

  1. Run the program normally
  2. Wait for memory to get out of hand.
  3. Run jmap: jmap -dump:format=b,file=dump.hprof <PID>
  4. Open the hprof file in EMM.

I usually start working with the histogram and dominator tree views to see if anything seems out of whack, then drill down from there.

VisualVM can be useful but seems much less efficient than EMM when working with a heap dump (EMM caches a lot of information on loading the heap dump). Netbeans Profiler is nice for getting the locations of allocations and for time profiling.

这篇关于Java内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆