bevacqua
bevacqua

Reputation: 48476

C# Usage of GC and how to trace a Memory Leak

I have a large C# server application, I'm interested in learning how the GC class works, and in particular what actions should I take to determine the source of a possible memory leak.

Are there any books on the subject, or is it not really that ellaborate?

Upvotes: 1

Views: 1690

Answers (6)

M0eB
M0eB

Reputation: 151

To complement the answers above, there are more recent videos on Channel9 with Maoni Stephens (Principal developer for the GC on the CLR team at Microsoft) that walk you through basics of GC, what developers should look out for, how they should troubleshoot, and some of the tools you can use. I found the explanation of how the GC works and the concept of generations and roots really useful.

Here is the first part of a 3 episode series :

http://channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-33-CLR-GC-Part-1

Upvotes: 0

Remus Rusanu
Remus Rusanu

Reputation: 294247

There is an excellent article by Rico Mariani: Tracking down managed memory leaks (how to find a GC leak). I used this technique often and is easy and efficient. And getting yourself familiar with a true debugger like Windbg is a bonus side benefit!

Upvotes: 1

Chris O
Chris O

Reputation: 5037

There is also the SciTech .NET Memory Profiler, our team has been using that successfully.

Upvotes: 0

Nick Martyshchenko
Nick Martyshchenko

Reputation: 4249

There are plenty of sources you can study.

I hope you don't miss basics:

  • CLR via C# 3rd Edition by Jeffrey Richter

I think before you go with details about GC, try to understand how IDisposable and resource management is handled:

GC specific:

Hope it helps to start.

Upvotes: 2

John Kraft
John Kraft

Reputation: 6840

Also not a book, but decent article. Memory Leak Detection in .NET

Upvotes: 1

StellarEleven
StellarEleven

Reputation: 556

Not a book, but our team has used the ANTS Memory Profiler with pretty good success for tracking down managed memory leaks. Their support section and included help walks you through the process of tracking down different types of memory issues. This doesn't include specifics on the GC class itself, just how to track down common mistakes (event handler deregistration, static variables, etc.).

Upvotes: 1

Related Questions