Massive Memory Leak - What am I doing wrong?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Stephen (anonymous_at_discussions.microsoft.com)
Date: 05/31/04

  • Next message: Kovalenko Dmitry: "ANN: IBProvider 2.4 [OLEDB for Interbase/Firebird]"
    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.


  • Next message: Kovalenko Dmitry: "ANN: IBProvider 2.4 [OLEDB for Interbase/Firebird]"

    Relevant Pages

    • New to n-tier (C# Web app / ASP.NET 1.1)
      ... My question in summary is "how do I call my data access ... for SQL server - the only places in the project where connection to the ... database is made), in their own folder within the VS project, therefore ... compiled into the one single dll with the rest of the app. ...
      (microsoft.public.dotnet.distributed_apps)
    • Re: Class instancing
      ... What I am presently trying to do is to create a DLL, ... > work-arounds that I can see to get around the automatic changing of the ... Create the DLL and use this as a Reference library in your database ... Copy the class from the library database and paste it into any ...
      (microsoft.public.access.modulesdaovba)
    • Re: VB DLL wont die
      ... I have a VB DLL which I wrote as part of a VB application. ... little of the VB graphic interface, and more intensive database ... I keep feeding the class PKs from the recordset, ... stopped execution there, I couldn't seem to get out of that event. ...
      (microsoft.public.vb.general.discussion)
    • Re: VB DLL wont die
      ... all), which lets the user input a bunch of data, then does the calculations ... It also saves the raw data into an Access database, ... from which it can retrieve old records and spit out the report again. ... I had developed a VB DLL which took care of all the database interactions, ...
      (microsoft.public.vb.general.discussion)
    • Re: How to handle custom-messages in VBA from a custom C++ DLL
      ... > start other threads when called external functions from a DLL when using ... If some component is doing an operation on the database, ... Are you saying that you are having a *modeless* dialog box? ... or use a separate process. ...
      (microsoft.public.vc.language)