OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
From: Joan Ramon López Gillué (jrlopezVISIONADVANCE.COM)
Date: Wed Oct 03 2001 - 02:43:41 CDT

  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    Hi Zlatko,

    Here's the code for the thread procedure. I cannot see anything wrong in it,
    but may be you (or other) will.

    =============================================================
    unsigned long CThreadApp::Thread()
    {
            CoInitialize(NULL);

            // Register an interface in the GIT
            IGlobalInterfaceTable *piGIT=NULL;
            CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL,
                                            CLSCTX_INPROC_SERVER,
                                            IID_IGlobalInterfaceTable, (LPVOID*)&piGIT);
            IDummyComponent *piDummy=NULL;
            piGIT->GetInterfaceFromGlobal(m_cookie, __uuidof(piDummy),
    (void**)&piDummy);

            // Sleep for a while
            Sleep(100);

            if (piDummy) { piDummy->Release();}
            piGIT->Release();

            CoUninitialize();

            return 0;
    }

    ===========================================================
    ... and here is the main()

    int main(int argc, char* argv[])
    {
            CoInitialize(NULL);

            HRESULT hr=S_OK;
            CThreadApp app;

            // Create instance of dummy component
            IDummyComponent *piDummy=NULL;
            hr = CoCreateInstance(CLSID_DummyComponent, NULL, CLSCTX_INPROC_SERVER,
                                            IID_IDummyComponent, (void**)&piDummy);
            // Register an interface in the GIT
            IGlobalInterfaceTable *piGIT=NULL;
            DWORD cookie = 0;
            hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL,
                                            CLSCTX_INPROC_SERVER,
                                            IID_IGlobalInterfaceTable, (LPVOID*)&piGIT);
            hr = piGIT->RegisterInterfaceInGlobal(piDummy, __uuidof(piDummy), &cookie);
            if (piDummy) piDummy->Release();

            // Start launching threads until key pressed
            cout << "Press any key to terminate..." << endl;
            while (!kbhit())
            {
                    app.LaunchThread(cookie);

                    MSG msg;
                    while(PeekMessage(&msg,NULL,0,0,FALSE))
                    {
                            GetMessage(&msg,NULL,0,0);
                            DispatchMessage(&msg);
                    }
                    Sleep(30);
            }

            cout << "Waiting for threads to terminate..." << endl;
            Sleep(3000); // Not too elegant, I know!

            piGIT->RevokeInterfaceFromGlobal(cookie);
            piGIT->Release();

            CoUninitialize();

            return 0;
    }

    ==================================================================
    ==================================================================

    -----Original Message-----
    From: Zlatko Michailov

    When you unmarshal from the GIT, you have a proxy created in your target
    apartment. How proxies are implemented, I don't know but they use memory for
    sure. The code of your ThreadProc might give us more information e.g. if you
    initialize the new threads as STA, then you definitely force the COM
    run-time to use your memory.

    Zlatko

    -----Original Message-----
    From: Distributed COM-Based Code [mailto:DCOMDISCUSS.MICROSOFT.COM]On
    Behalf Of Joan Ramon López Gillué
    Sent: Friday, September 28, 2001 7:30 AM
    To: DCOMDISCUSS.MICROSOFT.COM
    Subject: leak in GetInterfaceFromGlobal

    Hi all,

    I'm getting a strange memory leak when using GetInterfaceFromGlobal from a
    thread.

    Basically what I do is:

    1. CoCreate a dummy component "A" and get its "Ia" interface.

    2. Register interface "Ia" in the GIT with RegisterInterfaceInGlobal

    3. while (!_kbhit) {
            Create a thread which gets "Ia" from the GIT and then releases it.
            MessageLoop;
       }

    ====================================

    When I execute the program the Task Manager shows how memory used by the
    process raises
    in blocks of 4Kb (sometimes 8Kb).

    If I comment out the line where I call "GetInterfaceFromGlobal" (and nothing
    else) the memory leak stops.

    Any hint about what I can be doing wrong?

    Thank a lot

    ----------------------------------------------------------------
    Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    contains important info. Save time, search the archives at
    http://discuss.microsoft.com/archives/index.html .
    To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM

    ----------------------------------------------------------------
    Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    contains important info. Save time, search the archives at
    http://discuss.microsoft.com/archives/index.html .
    To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM

    ----------------------------------------------------------------
    Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    contains important info. Save time, search the archives at
    http://discuss.microsoft.com/archives/index.html .
    To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM