C# + COM Interop, deterministic release(C# + COM 互操作,确定性发布)
问题描述
COM 对象通常具有确定性破坏:它们在最后一个引用被释放时被释放.
COM objects usually have deterministic destruction: they are freed when the last reference is released.
在 C# - COM 互操作中如何处理?这些类没有实现 IDisposable
,所以我看不到触发显式 IUnknown::Release 的方法.
How is this handled in C# - COM Interop? The classes don't implement IDisposable
, so I see no way to trigger an explicit IUnknown::Release.
一个偶然的测试表明,未引用的 COM 对象被延迟收集(即垃圾收集器正在触发释放).对于需要积极释放的 OCM 对象,我该怎么办?(例如,持有大量或共享的关键资源)?
A casual test shows that unreferenced COM objects get collected lazily (i.e. the garbage collector is triggering the release). What should I do for OCM objects that need to be released aggresively? (e.g. holding large or shared critical ressources)?
原始问题:我们有一个 C# 应用程序大量使用 COM 库,并且它正在疯狂地泄漏.似乎问题在于 C++ 和 C# 代码之间"(我们可以访问两者),但我们无法确定.
Original problem: We have a C# application heavily using a COM library, and it is leaking like mad. It seems that the problems is "between" the C++ and the C# code (we have access to both), but we can't nail it down.
推荐答案
您可以使用 System.Runtime.InteropServices.Marshal 类来操作 COM 互操作引用.具体来说,您可能想看看 Marshal.释放ComObject.
You can manipulate COM interop references using the System.Runtime.InteropServices.Marshal class. Specifically you may want to have a look at Marshal.ReleaseComObject.
这篇关于C# + COM 互操作,确定性发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# + COM 互操作,确定性发布


基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01