Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. COM Object Released But DLL Still In Memory

COM Object Released But DLL Still In Memory

Scheduled Pinned Locked Moved C / C++ / MFC
comdebuggingperformancehelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Crazy Joe Devola
    wrote on last edited by
    #1

    Hi, I have a program that uses a COM object. At somepoint I try to release the object. After I do the release process, I can see using Process Explorer that the ActiveX DLL is still in memory. My code is below. Am I doing something wrong? Why is the DLL still in memory? ComReleaseTest.DLL is a test VB ActiveX DLL I wrote to debug this problem. It does nothing - all it has is one test sub which I am not even calling. #include "stdafx.h" #import "..\ProductTree\winpos\drv32\ComReleaseTest.dll" no_namespace _CComReleaseTestPtr m_Srv; int Close(); void ReleaseObject(); int main(int argc, char* argv[]) { HRESULT hResult; try { if ( TRUE ) { hResult = CoInitialize( NULL ); if ( hResult != S_OK ) { return 1; } } HRESULT hr = m_Srv.CreateInstance(__uuidof( CComReleaseTest ), NULL, CLSCTX_ALL); if (FAILED(hr)) _com_issue_error(hr); } catch(_com_error& e) { return (1); } Close(); return (0); } int Close() { long Result = 0; if ( m_Srv != NULL ) { TRY { ReleaseObject(); } CATCH_ALL(e) { TCHAR sError[255]; e->GetErrorMessage(sError,255); } END_CATCH_ALL } return ( (short)Result ); } void ReleaseObject() { // Disconnect from VB ActiveX try { m_Srv.Release(); } catch(_com_error& e) { // } free(m_Srv); m_Srv.Detach(); m_Srv = NULL; } The reason I am trying to track this is that I have anotehr program that at somepoint calls an InstallShield 5.5 setup. This setup.exe hangs at 99% and I found that if my program does not call a certain ActiveX then there is no problem with the setup.exe. So I am trying to release that ActiveX before calling setup.exe, but the COM DLL just stays in memory!

    S 1 Reply Last reply
    0
    • C Crazy Joe Devola

      Hi, I have a program that uses a COM object. At somepoint I try to release the object. After I do the release process, I can see using Process Explorer that the ActiveX DLL is still in memory. My code is below. Am I doing something wrong? Why is the DLL still in memory? ComReleaseTest.DLL is a test VB ActiveX DLL I wrote to debug this problem. It does nothing - all it has is one test sub which I am not even calling. #include "stdafx.h" #import "..\ProductTree\winpos\drv32\ComReleaseTest.dll" no_namespace _CComReleaseTestPtr m_Srv; int Close(); void ReleaseObject(); int main(int argc, char* argv[]) { HRESULT hResult; try { if ( TRUE ) { hResult = CoInitialize( NULL ); if ( hResult != S_OK ) { return 1; } } HRESULT hr = m_Srv.CreateInstance(__uuidof( CComReleaseTest ), NULL, CLSCTX_ALL); if (FAILED(hr)) _com_issue_error(hr); } catch(_com_error& e) { return (1); } Close(); return (0); } int Close() { long Result = 0; if ( m_Srv != NULL ) { TRY { ReleaseObject(); } CATCH_ALL(e) { TCHAR sError[255]; e->GetErrorMessage(sError,255); } END_CATCH_ALL } return ( (short)Result ); } void ReleaseObject() { // Disconnect from VB ActiveX try { m_Srv.Release(); } catch(_com_error& e) { // } free(m_Srv); m_Srv.Detach(); m_Srv = NULL; } The reason I am trying to track this is that I have anotehr program that at somepoint calls an InstallShield 5.5 setup. This setup.exe hangs at 99% and I found that if my program does not call a certain ActiveX then there is no problem with the setup.exe. So I am trying to release that ActiveX before calling setup.exe, but the COM DLL just stays in memory!

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      yaron klodovski wrote:

      Am I doing something wrong? Why is the DLL still in memory?

      The DLL won't get unloaded just because you've disposed of all the objects you got from it. The DLL stays loaded in case you want to create more objects. You could try using CoFreeUnusedLibraries[^] to unload the DLL (but be aware that CoFreeUnusedLibraries will only work instantly in single-threaded apartments[^].

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      C 1 Reply Last reply
      0
      • S Stuart Dootson

        yaron klodovski wrote:

        Am I doing something wrong? Why is the DLL still in memory?

        The DLL won't get unloaded just because you've disposed of all the objects you got from it. The DLL stays loaded in case you want to create more objects. You could try using CoFreeUnusedLibraries[^] to unload the DLL (but be aware that CoFreeUnusedLibraries will only work instantly in single-threaded apartments[^].

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        C Offline
        C Offline
        Crazy Joe Devola
        wrote on last edited by
        #3

        Thank you very much. You are a genius! Problem solved. :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups