ADO Close not releasing all memory - small leak

495 views Asked by At

I've isolated my code to just this - running it results in a small memory leak. Can anyone see why?

HRESULT hResult = CoInitialize(NULL);
if ((hResult != S_OK) && (hResult != S_FALSE))
    return;

_ConnectionPtr conn; 
hResult = conn.CreateInstance(__uuidof(Connection));
if (hResult != S_OK)
    {
    CoUninitialize();
    return;
    }

conn->CursorLocation = adUseClient;
conn->Open(sConnectionString, L"", L"", adConnectUnspecified);

if (conn)
    {
    conn->Close();
    conn.Release();
    conn=NULL;
    }

CoUninitialize();
return;

This is the sConnectionString, though I can't see anything that would cause memory to leak from the conn object:

"Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source="C:\Temp\acctprod.sdf"; ssce:database password='password';"

1

There are 1 answers

0
JeffR On

Using CoInitializeEx with COINIT_MULTITHREADED instead of just CoInitialize fixed the leak. But I'm not sure when/why to use COINIT_MULTITHREADED or COINIT_APARTMENTTHREADED?

HRESULT hResult = CoInitializeEx(NULL,COINIT_MULTITHREADED);