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:
When should we use these new modes?
Calling GC.Collect is generally discouraged, but as Rico points out here, there are legitimate circumstances where you know there is a large number of objects you’ll never need again. For example, at the end of a game level, when a custom Form is closed, or when a web form is finished, there may be a number of long-lived objects in generation 2 that are now dead. By calling an Optimized collection at this point you give the GC a chance to evaluate the heap, and have it decide if a collection will free enough memory to be worth it.
Forced and Default modes should generally only be used for debugging or testing scenarios, where you want to ensure objects are collected at a certain point in your application, or want to compare performance data. In future versions of the CLR, there may be new guidance for using Default, but for now, its use is discouraged.