A very geeky read: .NET Garbage Collection

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • A very geeky read: .NET Garbage Collection

      Ah, it was a slow evening, so I decided to liven it up by doing some technical reading.

      I found a facinating two part article giving a technical description of how .NET's garbage collector works.

      msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx

      msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx

      Managed memory gives a programmer a relief of worrying about forgetting to free an ununsed resource and attempting to use an already freed resource. The drawback is the performance overhead involved with maintaining the managed memory. Here's a quote from the article that discusses a goal for the .NET garbage collector:

      Microsoft's performance tests show that managed heap allocations are faster than standard allocations performed by the Win32 HeapAlloc function. These tests also show that it takes less than 1 millisecond on a 200Mhz Pentium to perform a full GC of generation 0. It is Microsoft's goal to make GCs take no more time than an ordinary page fault.


      A bold statement indeed!
    • RE: A very geeky read: .NET Garbage Collection

      Goal! Give me freaking break!

      You can't just say that a full GC pass on big chunks of allocated memory are going to take less than 1ms.

      How many blocks will you have to traverse?
      How many memory pages will you have to dork with?

      Good grief.
      I think some serious testing will show that their 1ms goal will remain a goal - and one on the horizon at that, especially with a 200Mhz pentium.

      Let's see Microsoft Word written in C#, and see it perform better. Or perhaps MS SQL server....
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • The brilliance with their memory allocation scheme is using a stack based layout where new objects are simply allocated at the top of the stack. This'll outperform a C/C++ allocation scheme using a linked list search looking for a block of memory big enough to hold the newed object. A process that is highly susceptible to cache misses & page faults.

      When the author talks of garbage collecting generation 0 objects, they are referring to most recently allocated objects residing at the top of the stack. The heuristic being most recently allocated objects are the most likely candidates to be disposed and garbage collected. Older objects make their way down the stack. Eventually an equilibrium is obtained in the application where generation 0 objects reside in the CPU cache. Garbage collection can then be accomplished without a cache miss or a page fault.

      Read the article...it's cool stuff.

      The next generation of MS SQL server (Yukon) will support an embedded CLR in the database engine allowing developers to write stored procedures in C# or VB.NET. It won't be as fast as pure Trans-SQL, but working in TSQL is like stepping back 20 years.