In my previous post about GC.AddMemoryPressure Tomer Gabel commented that people should not use this feature since its not the correct thing to do.

In addition to that Yuval Ararat wrote a post about this issue as well.

First of all, if I wasn’t clear enough in my first post, they are technically write BUT (and there is a big but here) there are situations, mainly in interoperability issues that might require us to better notify the GC that behind this small and insignificant .NET object lies a whole lot of unmanaged memory that is allocated and will only be released when this .NET object dies.

Calling GC.AddMemoryPressure will simply make the GC consider this object for who it really is, a memory hungry object that hides behind it a lot of unmanaged allocated memory.

Originally I just wanted to introduce this feature to people and make sure they know about it even though its quite esoteric and will mostly be used by applications with specific needs (and believe me, I know at least one application that could have benefited from this feature if it was available in .NET 1.1).

And Tomer, regarding the typos and stuff, I usually try to spell check and proof my posts, but some times they slip by 😉

  • Tomer Gabel

    While I still think that finalizers for unmanaged resources are inherently bad, I do agree that people sometimes (often?) forget using, Dispose statements etc.. That’s why when you do write finalizers, you should (a) make sure to wrap the unmanaged resources in a seperate class so that the GC does not have to promote the “bigger” classes that use them; and (b) make sure that the finalizer does call Dispose – and Disposes in turn calls GC.SupressPendingFinalizers( this ) – but also writes a warning to the log so you know you have an undisposed-of resource somewhere.

    As for the typos, no problem, just nitpicking 🙂