Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which managed classes in .NET Framework allocate (or use) unmanaged memory?

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?

like image 836
LBushkin Avatar asked Oct 04 '09 02:10

LBushkin


2 Answers

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.

like image 151
Coincoin Avatar answered Nov 06 '22 06:11

Coincoin


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.

like image 37
Scott Dorman Avatar answered Nov 06 '22 05:11

Scott Dorman