New In Orcas Part 3: GC Latency Modes

As you may know, there are different GC modes to choose from depending on the type of application you’re using:  Server GC, Workstation GC, and Concurrent GC (more info).  These settings are process-wide, set at the beginning of the process.  Once the GC mode is set, it cannot be changed.  In Orcas, we’ve added the…


New In Orcas Part 2: GC Collection Modes

In Orcas we’ve added an overload to System.GC.Collect(): void System.GC.Collect(int generation, System.GCCollectionMode mode) Where generation is the highest generation to collect (from 0 to System.GC.MaxGeneration) and mode can be: Default:  the same behavior if you called GC.Collect without specifying the mode.  Currently this is the same behavior as Forced, but this is subject to change…


New In Orcas Part 1: What we’ve been doing

The Orcas March CTP is out, and what does that mean for the Garbage Collector?  The GC team has been concentrating on three areas for this release: Bug fixes.  For Orcas, we’ve fixed several premature Out of Memory bugs, improved stability in certain stressful conditions, and even improved performance in some scenarios.   GC Collection Modes.  We’ve…


When GC.KeepAlive Doesn’t

The purpose of GC.KeepAlive(Object) is to tell the GC not to collect an object until a certain point.  For example: class MyObject{   ~MyObject()   {   Console.WriteLine(“MyObject Finalized”);   }                 public static void Main()   {      MyObject obj = new MyObject();      LongRunningMethod();      GC.KeepAlive(obj); // ~MyObject will NOT be run before this call      …   }} KeepAlive will ensure ~MyObject will not get run before LongRunningMethod gets called.  This is useful…


Object Resurrection

I’m sure many of you have heard the term “object resurrection” with respect to the GC.  It’s an interesting (but not very useful) way to illustrate object lifetimes and the role of finalization versus garbage collection.  Basically, it’s a way to reference an object that has been finalized.   Here’s a rough description of how…


How To Tell Which GC Mode Your Application Is Using

I posted previously about how to set the GC mode your application.  So now that you’re running your app, how do you know it’s running in that GC mode? If you’re using v1.0 or v1.1, the CLR loads a different dll based on which GC mode (mscorwks.dll for workstation, mscorsvr.dll for server).  You can use…


To Null or Not to Null

GC Myth: setting an object’s reference to null will force the GC to collect it right away.GC Truth: setting an object’s reference to null will sometimes allow the GC to collect it sooner. As much as you may want to, you can’t guarantee the GC will collect what you want, when you want it to….


Part 2 in Maoni’s Using GC Efficiently

Maoni posted Part 2 to Using the GC Efficiently.  A very in-depth article about Server, Workstation and Concurrent GC.  Check it out.


GCHandles, Boxing and Heap Corruption

A GCHandle is a struct used to hold onto a managed object to be used by unmanaged code.  With a GCHandle you can (among other things): Prevent an object from being garbage collected if unmanaged code has the only live reference to it Pin an object in memory, so it won’t be relocated in memory…


A Few Good GC Links

I keep a GC folder in my Favorites full of links to articles and blog posts about the .NET GC.  I thought it would be a good idea to consolidate them all into one blog post, for handy reference.  These are the articles I most often post as answers to questions on public newsgroups. If you…