How to research unmanaged memory leaks in .NET?

两盒软妹~` 提交于 2019-12-03 06:40:39

问题


I have a WCF service running over MSMQ. 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. Total CLR memory managed heap bytes remains relatively constant, while the process' private bytes increases over time. 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). I am not doing anything explicitly with COM or DllImports.

Thanks in advance!


回答1:


You can use Windbg to analyze the process Heap. There are some articles and cheat sheets showing how to do this, like Memory Leak Detection Using Windbg




回答2:


This blog will help you if you are willing to learn about windbg (http://www.microsoft.com/whdc/devtools/debugging/default.mspx).

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




回答3:


Make sure that you close the service client after using it. something like

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



回答4:


Ants Profiler is worth considering. As far as I can remember, you can download a trial version.



来源:https://stackoverflow.com/questions/2850098/how-to-research-unmanaged-memory-leaks-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!