Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run a .NET garbage collection from WinDbg?

I'm looking into why a managed process is using a lot of memory. Is there a way to run GC.Collect(3) from WinDbg, so that I can focus on the actual memory allocation?

like image 563
Roger Lipscombe Avatar asked Dec 02 '08 14:12

Roger Lipscombe


3 Answers

I don't think there is any way to run a .NET garbage collection from WinDbg, but I also don't think it is necessary.

See Rico Mariani's Performance Tidbits - Tracking down managed memory leaks (how to find a GC leak) for information about finding out what kind of stuff is on your heap.

Additional possibly useful links:

  • When to call GC.Collect()
  • Scott Dorman - .NET Memory Management – Resources
like image 78
Grant Wagner Avatar answered Sep 22 '22 08:09

Grant Wagner


I do not believe that you can trigger a GC from WinDbg.

Here are some useful tools that I have come to rely on for memory allocation tracking:

  • SOSEX -- a further extension for WinDbg to complement SOS which adds !dumpgen to dump objects from a particular generation (great for figuring out what is on the LOH and in Gen 2) and the !refs command which will give the parent refs for an object.
  • .Net Memory Profiler -- this is a very useful tool when running interactively but it also contains an option to load from a dump file. This gives a reasonably intuitive way to track through memory usage. Easily worth the 250USD price but they also have a 14 day eval.
like image 25
Dave Ganger Avatar answered Sep 20 '22 08:09

Dave Ganger


WinDBG is first and foremost a Win32/Kernel Debugger. So you may want to try one of the managed debuggers, like mDBG. But I used to do .NET Debugging support for MSFT, and I've never needed anything like that to troubleshoot memory leaks.

like image 23
Cory Foy Avatar answered Sep 19 '22 08:09

Cory Foy