Wednesday, February 10, 2010

@ntdebugging Q&A Question Opportunity

The team responsible for the  Advanced Windows Debugging and Troubleshooting blog is looking for your “burning debug questions” that they hope to answer in an upcoming Q&A article.  You can tweet your questions to @ntdebugging for consideration for the article.  If your remotely interested in Windows debugging, and anything debugging related, I highly recommend checking them out!

Unfortunately, I am finding it particularly hard to frame my question into 140 characters this morning, and short of a vertigo-like experience where I realize “I know Kung-Fu”, I thought I’d post my question here in hopes to get my question answered by the team that does know kung fu.

Realize that anything posted here, especially if false, is due to my imperfect understanding of experiences and knowledge imparted by Advanced Windows Debugging and Troubleshooting, Tess Ferrandez (and her many compatriots!), Jeffrey Richter,  and the Godfather of the Debugger, John Robbins

The Setup

.NET allocates memory for each generation’s heap (0, 1, 2, LOH) in segments to get a continuous block of memory when it attempts to satisfy an allocation request, after a collection, and can’t.  This memory for each heap will likely level off as the application “warms up”, except potentially for generation 2, and large object heap.  During a garbage collection, each heap (0, 1, 2) is swept and compacted, except for the large object heap (LOH), which is just swept. 

I understand the ‘sweep’ part of a collection to mean that the GC identifies which objects are no longer rooted and are available for collection (or finalization) and that ‘compact’ means that the addresses that are still alive in a heap are reorganized so that the heap has more continuous memory available to it.   As the budget for each segment within the heap is exceeded, .NET will allocate another segment in order to fulfill allocations if it can.

The Question

My question comes down to what happens to that memory in each heap, that might not be used by the application (committed) any longer, but is still reserved by .NET?  When is it released back to the OS? 

I’ve heard of rituals such as forcing Windows itself into low memory condition so that it asks each process to give up any reserved memory, or minimizing a process, and then restoring it, which essentially does the same thing.  These are just rumors and I’d prefer to know. 

There are also rumors of something involving chickens, but I’d rather not go there…no one likes rituals, they are unreliable and often messy (think of the chickens!).