0

I am working on a C# 4.0 managed code application. I am using external DLLs which are not CLS compliant.

Do I need a memory leak detection tool to check for memory leaks in the DLLs? If yes what are the best tools out there?

Mustafa Ekici
  • 7,263
  • 9
  • 55
  • 75
om471987
  • 5,398
  • 5
  • 32
  • 40
  • 3
    do you suspect a memory leak? – Mitch Wheat Feb 02 '12 at 15:34
  • 2
    Related question: http://stackoverflow.com/questions/2526037/why-can-net-not-have-memory-leaks/2526058#2526058 – Oded Feb 02 '12 at 15:35
  • there is no "best tool" for this... it depends always on what the DLLs do - for example I have some DLLs which use unmanaged memory, other DLLs are native etc. No tool handles all of these equally well... – Yahia Feb 02 '12 at 15:36
  • No. But I have to check memory leaks every time as a part of our process. Thanks – om471987 Feb 02 '12 at 15:36
  • Will the program need to be running for long periods of time with 100% uptime? Should it have a rather large memory footprint? Will it be running in an environment with low amounts of free memory? I ask because in many cases it just doesn't matter if there is a memory leak as long as it's not really huge. – Servy Feb 02 '12 at 15:38
  • Also, asking for a "best" whatever here is not deemed constructive. At least give some parameters for judging "bestness". – Oded Feb 02 '12 at 15:39
  • 1
    It's typically not good to ask for a "best _____" since that's subjective, but I still think it's a good question from the standpoint of, "Can there be memory leaks in .NET" – John Ruiz Feb 02 '12 at 15:40
  • Yup. Sry for that. I will keep that in mind – om471987 Feb 02 '12 at 15:43
  • @Servy Yes we need. We have a multi threaded app which will integrate with other apps. So from our side we need high performance – om471987 Feb 02 '12 at 15:46

4 Answers4

2

Even in managed code, you can have memory leaks. I would not dig into memory leaks unless you actually find one, though.

If you do need to look into a leak, then I would suggest ANTS Profiler, however this has its limits, so it should be taken on a case by case basis.

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
  • I was going to look to see if I could find a good reference about .Net code having memory leaks, however the link that Oded has, adresses this pretty well. – Justin Pihony Feb 02 '12 at 15:39
1

Yes, it is possible to have memory leaks in .NET. It is even possible to have them when you're using nothing but the base class library, because many of those classes themselves make calls into unmanaged code.

I once had a memory leak because I didn't dispose a System.DirectoryServices.SearchResultCollection after enumerating over it.

However, I don't know what leak detection tools might be available.

John Ruiz
  • 2,371
  • 3
  • 20
  • 29
1

You can use a tool like CLR Profiler,VSTS Profiler, .NET Memory Profiler or CLR Profiler to check your object size etc, as they say you can Find Memory Leaks and Optimize Memory Usage in any .NET Program.

Mustafa Ekici
  • 7,263
  • 9
  • 55
  • 75
1

You can use the free WinDbg, SOS and GCRoot do diagnose memory leaks. David Anson shows you how on this blog post. Rico Mariani also has a good blog post on using WinDbg and SOS.

Other products like JustTrace, dotTrace and ANTS Profiler can help you diagnose these kinds of issues.

Phil Bolduc
  • 1,586
  • 1
  • 11
  • 19