【发布时间】:2011-08-05 12:36:24
【问题描述】:
通过互操作生成的接口从 c# 使用的第 3 方 com 模块正在泄漏内存
第3方c++方法签名为:
somemethod(....., long** param3, long** param4)
生成的互操作方法是:
somemethod(...., IntPtr param3, IntPtr param4)
最后 2 个参数由 umanaged dll 分配数组,并从 c# Marshal.CoMemFree 中释放(不记得确切的 sig atm)
通过 com 接口使用 C++ 中的相同方法并以相同方式释放不会产生泄漏
从命令行使用 tlbimp 会产生:
TlbImp : warning TI0000 : At least one of the arguments for
'Sometype.somemethod' cannot be marshaled by the runtime
marshaler. Such arguments will therefore be passed as a pointer and may
require unsafe code to manipulate.
我发现很长的**参数无法自动编组令人惊讶。
比.net更懂c++(不包括com黑魔法),但是实现.net端...
访问和释放在 param3 和 param4 中传回的内存的正确方法是什么。我怀疑他们应该是“out IntPtr”?
【问题讨论】:
标签: .net c++ memory-leaks interop marshalling