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

耗尽温柔 提交于 2019-12-01 17:24:33

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!