1

I have a .net application (running as a windows service). From time to time it starts memory leaking (using 1GB+ of RAM). How do I find the cause of this memory leak? Which tools are there and how do you use them?

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222

5 Answers5

2

I used WinDbg and the SOS-extesion with success for debugging memoryleaks in .NET applications.

Have a look here and here to get a start. I also recommend Tess Ferrandez' blog for more information about debugging .NET with WinDbg

sloth
  • 99,095
  • 21
  • 171
  • 219
1

you can start from here: http://msdn.microsoft.com/en-us/library/ff650691.aspx the tool is free and it worked for mr in the past, even if it is not easy to use. There is commercial options too, but never used.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
1

In similar situations I use to pick up Ants memory profiler or similar and check the count of allocated objects for objects that are allocated more than expected. I especially look at forms and other objects with events bound to them. This sometimes gives a good start of what objects that are involved in the leak. From there it is the usual detective work to find out the "hidden" reference to those objects.

Albin Sunnanbo
  • 46,430
  • 8
  • 69
  • 108
0

I used Ants once and it helped me to solve my problem. As Felice points, there are some free tools that can be used too.

Most of the time your memory leaks are from undisposed objects. Try wrapping all your connections in an using block. And if you are any COM+ objects (for example GDI+ objects - Bitmaps, etc.), call Dispose() always when you finish using them. Also forgetting to unregister event handlers eats a lot of memory.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Edgar Hernandez
  • 4,020
  • 1
  • 24
  • 27
0

I can recommend to use .NET Memory Profiler by Scitech (http://memprofiler.com/) for finding the memory leak in your .NET application.

Simon Fischer
  • 3,816
  • 3
  • 23
  • 32