Click to See Complete Forum and Search --> : CoCreateInstance leak on Win2008


listentwice
May 27th, 2008, 04:14 PM
This is very simple windows service (COM server) using ATL/COM with VS2005. I also have a console app (COM client) performing a CoCreateInstance() and a subsequent release.

When run on W2K3/SP1 everything is fine, no memory leak. However, on W2K8 it leaks a few bytes (in the service) for every client call to CoCreateInstance(). I have the client code in a sizable loop so that the leak is large enough to show up in the Task Manager (Private Working Set) memory. The memory of the service increases 8K-18K bytes for the loop below.

I have tried it without a explicit constructor or destructor (and many other things) but no change. I expect I am missing something obvious but I don’t see it. I have stripped the VS2005 project down so that it is fairly bare-bones code. So I can post larger sections of it here, or email it if needed.

Local Server code:

_Module.dwThreadID = GetCurrentThreadId();
CoInitializeEx(NULL, COINIT_MULTITHREADED);
CSecurityDescriptor sd;
sd.InitializeFromThreadToken();
CoInitializeSecurity(sd, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
_Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,
REGCLS_MULTIPLEUSE);


Local Client code:

INTELDCBLib::IIoControl* pControl;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
for (int k = 0; ULONG(k) < 2000; k++) {
CoCreateInstance(INTELDCBLib::CLSID_IoControl,
NULL,
CLSCTX_ALL,
INTELDCBLib::IID_IIoControl,
(void **)&pControl);
pControl->Release();
pControl = NULL;
}


Server Object:

class ATL_NO_VTABLE CIoControl :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CIoControl, &CLSID_IoControl>,
public IDispatchImpl<IIoControl, &IID_IIoControl, &LIBID_INTELDCBLib>
{
public:
CIoControl() {};
~CIoControl() {};

DECLARE_REGISTRY_RESOURCEID(IDR_IOCONTROL)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CIoControl)
COM_INTERFACE_ENTRY(IIoControl)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

public:
private:
};


Thanks! J