Massive Memory Leak - What am I doing wrong?
From: Stephen (anonymous_at_discussions.microsoft.com)
Date: 05/31/04
- Previous message: vaas: "Schema.ini"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 31 May 2004 07:51:03 -0700
Hello,
Our application uses database plugins so that we can just replace a DLL and use a different databae provider.
I am working on an MS SQL Server plugin using OLEDB and I have been using the prsample sample code provided with the MDAC 2.8 SDK as a guide.
My problem is that every COM function call in my plugin is leaking when my application loads the DLL and connects to the database through function calls into the DLL.
If I just instantiate my DB class in a executable and call the exact same functions, there is no leak.
So, there is something about calling functions in a DLL that causes the COM calls to leak but I don't know what I need to do to stop it.
Here is an example of code that will leak when call from the DLL but won't when called from an executable. It is very much like the prsample code.
In this instance, Purify reports that pIDataInitialize->CreateDBInstance leaks. I have Purify'd complete runs of our application and every single COM call(i.e. QueryInterface, SetCommandText, Execute) reports as a leak and memory use goes through the roof say after 1000 database inserts. I am releasing everything that the prsample code releases, but using the DLL to get to the database class leaks, instantiating the database class directly does not.
Code Sample, Note zchar is either char or wchar_t depending on UNICODE setting.:
HRESULT DBAPI_MSSQL::zCreateDataSource(IUnknown** ppUnkDataSource, const zchar* in_pDB, const zchar* in_pUser, const zchar* in_pPasswd, const zchar* in_pDBHost)
{
HRESULT l_hr;
IDataInitialize* pIDataInitialize = NULL;
IDBInitialize* pIDBInitialize = NULL;
// We will create the DataSource object through the OLE DB service component IDataInitialize interface,
// so we need to create an instance of the data initialization object.
l_hr = CoCreateInstance(CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER , IID_IDataInitialize, (void**)&pIDataInitialize);
if ( l_hr == S_OK )
{
// Use IDataInitialize::CreateDBInstance to create an uninitialized DataSource object for the chosen provider.
// By using this service component method, the service component manager can provide additional functionality
// beyond what is natively supported by the provider if the consumer requests that functionality.
l_hr = pIDataInitialize->CreateDBInstance(CLSID_SQLOLEDB, NULL, CLSCTX_INPROC_SERVER , NULL, IID_IDBInitialize, (IUnknown**)&pIDBInitialize);
if ( l_hr == S_OK )
{
// Initialize the DataSource object by setting any required
// initialization properties and calling IDBInitialize::Initialize
l_hr = zDoInitialization(pIDBInitialize, in_pDB, in_pUser, in_pPasswd, in_pDBHost);
}
else
SetLastError(l_hr, ZTEXT("CreateDBInstance Error"));
}
else
SetLastError(l_hr, ZTEXT("CoCreateInstance Error"));
*ppUnkDataSource = pIDBInitialize;
if( pIDataInitialize )
pIDataInitialize->Release();
return l_hr;
}
Any help is appreciated,
Stephen.
- Previous message: vaas: "Schema.ini"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|