【发布时间】:2016-01-20 12:03:47
【问题描述】:
我创建了一个 com 可见的 c# dll。我有一个工厂方法来创建对象。我可以在 c++ 上使用和创建对象,但似乎对象没有被释放。我怎样才能释放它们。要清楚检查代码
-------------------c#------------------------
public interface IFoo()
{
void foo();
}
public class A:IFoo
{
//interface implemented here.
}
public interface IClassFactory
{
IFoo create();
}
public class TestFactory:IClassFactory
{
public IFoo create()
{
return new A();
}
}
--------------------C++-------
IClassFactory * ptrClassFactory;
CoInitilize(ptrClassFactory);//
IFoo * mObject = ptrClassFactory->create(); //this object is now garbage colledted //or so ?
// delete mObject; gives error on my case.
【问题讨论】:
-
它创建一个新的 A 类并将其返回为 IFoo ,查看 IClassFactory imp。
-
对不起,反过来读;那么,你是如何从你的 C++ 消费者那里释放 COM 对象的呢?
-
这是我目前的问题,我无法释放它们。如果我调用 delete * fooPtr ,我的 c++ 代码就会崩溃。我观察了内存使用情况,发现只要创建新对象,我使用的内存就会变大。
-
@RowlandShaw 是的,我的意思是 mObject->Release();
标签: c# c++ memory-management com-interop