I have a native C++ ATL in-proc COM server. A separate test program
- calls
CoInitialize()
, - calls
CoCreateInstance()
, then - calls
Release()
on the pointer, - then calls
CoUnitialize()
and exits.
If I run the test program under Visual C++ debugger the debug CRT reports a single memory leak and each time the allocation number is the same.
I used an allocation hook and found out that the object not being returned to the heap is the class factory object.
So basically the following happens:
- the program calls
CoCreateInstance()
- COM internally calls
DllGetClassObject()
- ATL instantiates the factory and passes ownership to the caller (COM internals)
and then the factory is never released - I don't see enough calls to Release()
of the class factory.
What is happening? Is that a defect in COM runtime?