views:

209

answers:

6

Hi

I have a windows service and it turns out I have a System.OutOfMemoryException after some time. Can you recommend some tools that would detect a memory leaks. I don't know if there can be a memory leak in .NET since it uses a gargage collector. But I remember I used BoundsChecker for C++ applications where memory leaks are typical programmer problem.

I use MS Visual Studio 2008 Enterprise Edition.

+5  A: 

red-gate has nice tools for .net, one of them is memory profiler: Ants Memory Profiler

Numenor
+6  A: 

I once recommended a coworker ran FXCop on a solution where he was getting an OutOfMemoryException. He then followed its advice on calling Dispose as appropriate and the problem was fixed.

I'm not saying that will fix the issue in your case, but it may. In his case it was event handlers not being unregistered. Calling Dispose on an object he was using caused the event handlers to be properly unregistered and the problem went away.

If you want to spend money on a profiler, I recommend JetBrains dotTrace. As of version 3.1, it has a feature that will help you a lot (though too will FXCop, which is free):

dotTrace 3.1 gives you another means for spotting memory leaks — finalized objects. You can now see all objects that were deleted by the finalizer and not properly disposed of in the code of your application.

RichardOD
+1 FxCop does an excellent job of letting you know when you should Dispose, implement IDisposable and follow the Disposable pattern.
Jesse C. Slicer
+4  A: 

Ants Profiler by Red Gate Software is what we use.

It is certainly possible to have memory leaks in .Net if you are using unmanaged objects or not disposing of objects that require it. Any object that has a Dispose or Close method should be disposed by wrapping them in a using block or by calling their Dispose or Close methods.

JohnForDummies
+1  A: 

If you really want to know what is going on, there is nothing like windbg with sos.dll to find these kinds of problems (that is, until VS 2010 is released).

Otávio Décio
+1  A: 

Ants Profiler is pretty good. Beside that i also use .Net Profiler from Scitech.

Adrian Faciu
+1  A: 

The EQATEC free profiler is very good and has helped me out in the past (and present) -

http://www.eqatec.com/tools/profiler

Also, you can search MSDN for the "CLR Profiler" which is a free tool from Microsoft.

Kris Krause