我創建了com可見的c#dll。我有一個工廠方法來創建對象。我可以在C++上使用和創建對象,但似乎該對象沒有被釋放。我怎樣才能釋放它們。要清除檢查代碼如何釋放c上創建的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++代碼就會崩潰。我觀察了內存使用情況,並發現只要創建新對象,我使用的內存就會變得更大。 –