I am using COM to initialize a C# .NET class through c++ unmanaged code, and I am detecting a memory leak even in a very basic program:
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
ComClass::IClass1 *_comClass1;
HRESULT hr = CoCreateInstance(__uuidof(ComClass::Class1),
0,
CLSCTX_INPROC_SERVER,
__uuidof(ComClass::IClass1),
reinterpret_cast<void**>(&_comClass1));
_comClass1->Release();
CoUninitialize();
return 0;
}
the C# class is also super simple:
[ComVisible(true), Guid("A95C4F43-65B0-4706-94D1-BEE2EF416766")]
public interface IClass1
{
}
[ComVisible(true), Guid("4670C9CD-0501-4274-BF03-E1FF65A77FEC")]
public class Class1 : IClass1
{
public Class1()
{ }
}
And still I'm detecting memory leaks. I'm using GlowCode and Purify for detecting the leaks, but even without them I can see the memory usage rising.
Am I not using CoCreateInterface correctly? what am I missing?
clarification
This is just a small program I created to simulate the problem. In my real program there are a lot of CoCreateInstance calls, and the VM size rises to around 1.5GB, surely this can't be normal... In addition, I can see using perfmon that the process' private bytes are rising, while the .Net CLR Memory bytes in all Heaps doesn't. Also GlowCode can monitor the mananged heap and does not point to a memory leak in the managed part...