views:

166

answers:

3

Is there a known (documented) set of .NET types that allocate memory in the unmanaged portion of the process' memory?

For example, Microsoft documents that the WPF infrastructure allocated unmanaged memory for its retained rendering model in order to optimize performance. Are there other such portions of the .NET framework that utilize large amounts of unmanaged memory?

+1  A: 

As far as I know, there is no single document that describes or identifies which classes in the framework use unmanaged resources. The MSDN documentation for the specific class may, but that would require you to look at specific classes.

Overall, it's a safe bet that many of the classes make use of some unmanaged code at some point. For instance, many of the Windows Forms controls are simply wrappers around the Win32 controls so they make use of unmanaged resources.

Scott Dorman
+4  A: 

If it implements IDisposable there is a very good chance it owns unmanaged data, or it's owning a managed class that ultimately owns unmanaged data. If it has Finalize(), it's sign that it directly owns unmanaged data.

As a rule of thumb, if it implements IDisposable, then Dispose() it as soon as you're done.

Coincoin
Corrected to "IDisposable." Also, the more reliable rule is if it implements a finalizer, it almost certainly owns unmanaged data.
bobbymcr
Indeed - most `IDisposable` items *don't* (directly) do anything unmanaged - but they chain to someting that *might*. For example, there is an `IDisposable` in iterator blocks - but nothing unmanaged.
Marc Gravell
A: 

You need to be careful when a class implements IDisposable. This usually indicates usage of unmangaged resources, that is however not limited to memory but might also be filehandles, sockets etc.

A good indicator for this is when the class uses an IntPtr.

Johannes Rudolph