检测垃圾收集的附加事件处理程序
我正在继承一个存在许多内存漏洞的现有应用程序。我怀疑它们是由订阅但从未释放的事件处理程序引起的。我可以使用哪些工具或资源来帮助识别所保留的对象,即使这些对象由于打开的事件处理程序而超出范围?
I'm inheriting an existing application that has a number of memory holes. I suspect they are caused by event handlers that are subscribed but never released. What tools or resources can I use to help identify the objects that are being held on to even after they have gone out of scope because of an open event handler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经成功使用 redgate 的 ANTS 内存分析器追查类似问题。它不是一个便宜的产品,但根据我的经验,它被证明非常有用并且物有所值。
I've had success using redgate's ANTS memory profiler to chase down similar issues. It's not an inexpensive product, but in my experience it's proven very useful and been worth the cost.
JetBrains 还有一个内存分析器:dotTrace Memory。我已经得到它,但还没有充分使用它来提出建议。它也不是免费的(除非您在用户组中赢得了许可证)。 :)
我还会检查以确保其类实现 IDisposable 的所有对象均已正确处置。即使发生异常,
using
块也会确保这一点。虽然这涉及非托管资源而不是内存,但实际上可能没有什么区别。另请参阅检测“泄漏的”IDisposable 对象,其中提到了多个内存分析器。
JetBrains also has a memory profiler: dotTrace Memory. I've got it but haven't used it enough to make a recommendation. It's not free either (unless you win a license at a user's group). :)
I'd also check to insure that all objects whose classes implement IDisposable are properly disposed. A
using
block will insure this even if an exception occurs. While that involves unmanaged resources rather than memory, in practice there may be little difference.See also Detecting "leaked" IDisposable objects, which mentions multiple memory profilers.