.NET Framework 中的哪些托管类分配(或使用)非托管内存?

发布于 2024-08-07 02:30:46 字数 134 浏览 3 评论 0原文

是否有一组已知(已记录)的 .NET 类型在进程内存的非托管部分中分配内存?

例如,Microsoft 记录称,WPF 基础结构为其保留的渲染模型分配了非托管内存,以​​优化性能。 .NET 框架中是否还有其他此类部分使用大量非托管内存?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮光沉寂 2024-08-14 02:30:46

如果它实现了 IDisposable,那么它很有可能拥有非托管数据,或者它拥有一个最终拥有非托管数据的托管类。如果它有Finalize(),则表明它直接拥有非托管数据。

根据经验,如果它实现了 IDisposable,那么完成后立即 Dispose() 它。

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.

时光倒影 2024-08-14 02:30:46

据我所知,没有一个文档可以描述或标识框架中的哪些类使用非托管资源。特定类的 MSDN 文档可能会出现,但这需要您查看特定类。

总的来说,可以肯定的是,许多类在某些时候会使用一些非托管代码。例如,许多 Windows 窗体控件只是 Win32 控件的包装器,因此它们使用非托管资源。

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.

单调的奢华 2024-08-14 02:30:46

当类实现 IDisposable 时,您需要小心。这通常表示非托管资源的使用,但不限于内存,还可能是文件句柄、套接字等。

对此的一个很好的指示是类何时使用 IntPtr

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文