objects. And global objects are destroyed in random
object in its destructor. So what happens in your case
(e.g. global object). Then you try to access them in that
object's destructor and you crash.
instead. Note I'm assuming your singleton is a regular
C++ object. If you've attempted a COM singleton, now
hosted in DLLs.
Here is a question about COM singleton object and static members
I have a COM Singleton object in a DLL that is instantiated in a EXE
application. When I close the EXE app, the DLL is unloaded and a call
to FinalRelease() function is executed for a COM Singleton object
before it is destroyed . The problem is that when the code tries to
access some static members during this time, the application crashes.
What is the lifetime of the static members in this case? Can we assume
that static members are still valid when the COM singleton object's
FinalRelease() function is called?
We were using a previous version of ATL before and it was working fine.
But the problem appeared I think when we ported the code to VS2005 with
Here is a description of what is happening. You can see the stack below
1) OmniDir.exe is the EXE application. You can see in the stack that it
is closing, then some calls are made in msvcr80d.dll and other DLLs.
2) After that, my DLL GxResource.dll is unloaded when
DllMainCRTStartup() is called.
3) This eventually calls FinalRelease() on my COM singleton object
CResource before it is destroyed
4) The CDisplayHelper::Terminate() static function is finally called
and this function tries to access static members which in turn crash
the application because these members are invalid at this point.
ATL::CComObjectCached<CResources>::`scalar deleting destructor'()
::`scalar deleting destructor'()
ATL::`dynamic atexit destructor for '_AtlComModule''()
_CRT_INIT(void * hDllHandle=0x07710000, [...])
__DllMainCRTStartup(void * hDllHandle=0x07710000, [...])
_DllMainCRTStartup(void * hDllHandle=0x07710000, [...])
msvcr80d.dll!doexit(int code=0, int quick=0, int retcaller=0)
Any idea on what is happening here?