Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to research unmanaged memory leaks in .NET?

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!

like image 753
Brandon Avatar asked May 17 '10 14:05

Brandon


People also ask

How will you find memory leaks and inefficient memory for a .NET application?

To find memory leaks and inefficient memory usage, you can use tools such as the debugger-integrated Memory Usage diagnostic tool or tools in the Performance Profiler such as the . NET Object Allocation tool and the post-mortem Memory Usage tool.

What is unmanaged memory in C#?

Unmanaged resources are generally C or C++ code, libraries, or DLLs. These are called unmanaged because the coder has to do the memory management (allocate memory for the object and clean the memory after the object is no longer required). These can file the handles, database connections, etc.


2 Answers

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

like image 183
Remus Rusanu Avatar answered Oct 08 '22 01:10

Remus Rusanu


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

like image 36
Carlos Mendible Avatar answered Oct 08 '22 02:10

Carlos Mendible