Whidbey BCL the Easy Way: Memory Pressure

I thought I would share some of the things I am putting in my talk. They may already be old news to some of you (which seems such a funny statement considering the product is only in alpha!) but to those of you who haven’t ventured in, I would love to leave a crumb trail to entice you to look further.

The class for Garbage Collection, System.GC, has two new methods: AddMemoryPressure and RemoveMemoryPressure.

Although the way GarbageCollecton works is pretty complex (and fascinating) here’s a simplified explanation. GarbageCollection is triggered by the amount of memory being used by your managed objects and based upon different triggers, it goes and cleans up objects that are no longer being used. If one of those managed objects owns an unmanaged object, that unmanaged object’s memory allocation is not taken into account. Imagine the confusion (and inefficiency and possibly worse…) created when a small managed object instantiates a very large unmanaged object.

Using these new methods, you can add or remove a value that is used in the GC’s calculations that help trigger it’s functionality. The value that you pass in could literally represent the size of the unmanaged object, or just be your own value that helps to almost “rate” or “rank” the priority of the object.

If you don’t have the Whidbey alpha, you can still read more about these methods online in the SDK Documentation. AddMemoryPressure  RemoveMemoryPressure . I have to say that the explanations in the documentation are really very clear and I recommend that you look into them for further details. Also Brad Abrams wrote a much more indepth explanation of Memory Pressure in December.

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.