简体   繁体   English

如何研究.NET中的非托管内存泄漏?

[英]How to research unmanaged memory leaks in .NET?

I have a WCF service running over MSMQ. 我有一个在MSMQ上运行的WCF服务。 Memory gradually increases over time, indicating that there is some sort of memory leak. 内存随着时间的推移逐渐增加,表明存在某种内存泄漏。 I ran the service locally and monitored some counters using PerfMon. 我在本地运行该服务并使用PerfMon监控一些计数器。 Total CLR memory managed heap bytes remains relatively constant, while the process' private bytes increases over time. 总CLR内存管理堆字节保持相对恒定,而进程的私有字节随时间增加。 This leads me to believe that there is some sort of unmanaged memory leak. 这让我相信存在某种非托管内存泄漏。 Assuming that unmanaged memory leak is the issue, how do I address the issue? 假设存在非托管内存泄漏问题,我该如何解决这个问题? Are there any tools I could use to give me hints as to what is causing the unmanaged memory leak? 是否有任何工具可以用来向我提供有关导致非托管内存泄漏的提示? Also, all my service is doing is reading from the transactional queue and writing to a database, all as part of a DTC transaction (handled under the hood by requiring a transaction on the service contract). 此外,我所有的服务都是从事务队列中读取并写入数据库,所有这些都是DTC事务的一部分(通过要求服务合同上的事务来处理)。 I am not doing anything explicitly with COM or DllImports. 我没有明确地使用COM或DllImports做任何事情。

Thanks in advance! 提前致谢!

You can use Windbg to analyze the process Heap. 您可以使用Windbg来分析进程堆。 There are some articles and cheat sheets showing how to do this, like Memory Leak Detection Using Windbg 有一些文章和备忘单显示了如何执行此操作,如使用Windbg进行内存泄漏检测

This blog will help you if you are willing to learn about windbg ( http://www.microsoft.com/whdc/devtools/debugging/default.mspx ). 如果您愿意了解windbg( http://www.microsoft.com/whdc/devtools/debugging/default.mspx ),本博客将为您提供帮助。

http://blogs.msdn.com/tess/default.aspx http://blogs.msdn.com/tess/default.aspx

Make sure that you close the service client after using it. 确保在使用后关闭服务客户端。 something like 就像是

try {
... do work ...
Close();
} ... exception handling ... {
Abort();
}

Ants Profiler is worth considering. Ants Profiler值得考虑。 As far as I can remember, you can download a trial version. 据我所知,您可以下载试用版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM