Eran Sandler has a new post on his blog describing the use of GC.AddMemoryPressure in .Net 2.0.
The comment from Tomer Gabel is quite accurate beyond the typo rants. this is a bypass of a managed vs unmanaged. if you have to use unmanaged COM objects then the architecture of come and the existant of proxy stab is limiting the removal of an unused COM.
But on the other hand detemrmining the estimated memory is kind of a detur for a real problem wich is the usage of unmanaged code in a managed environment.
How much time will it take to conver the project fully to managed code?
will your suppliar give you the ability to use his API from managed environment?
these are the project issues that you might look at when thinking about the problems that arise later on when using this type of scanarios and the solution the framework supplies for this type of issues.
it seems to me that Microsoft recognises the need to support elaborate scanarios evolved from the tendency it has to revolutionaize the development field every couple of years. they feel the needs of their customers that invested money into now obsolete technology but fail to implement that bridge in a more fluid way.
if you whould look at porting asp to or at any other change they made the microsoft team forgot the VB4->VB5->VB6 days or VC4->VC5->VC6. smooth transitions whould have made the need to havew managed and unnmanaged code together a thing of the past.
i think i can see the need to reinvent yourself as a survival issue but what about the integrators? what about the solution providors? what will the vendors of technology say to their customers?
this workaround to this problem is not what i whould assume as the “right” solution.
porting the logic over the technology is a better solution.
i see the same happening when the new SQL version will come and people will start asking in user groups this: “how can i call a stored proc from C# managed SQL code?” “how can i call unmanaged code from managed SQL code?” and more.
this managed unmanaged issue is not new.
i see no way to solve it. unless we get the microsoft or any other team to pick the glove and create some sort of a standard in development that will ensure simple porting of logic above technology.


  1. […] 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 😉 […]

Speak Your Mind


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