views:

109

answers:

4

I'm faced with the problem that my applications global variable destructors are not called. This seems to occur only if my application successfully connects to an oracle database (using OCI).

I put some breakpoints in the CRT and it seems that DllMain (or __DllMainCRTStartup) is not called with DLL_PROCESS_DETACH, thus no atexit() is called which explains why my destructors are not called. I have no idea why this happens.

I realize that this is probably not enough information to be able to indicate the cause, but my question is: What would be a good start to look for the cause of this problem?

This is a list of things I already tried:

  • search the net for solutions
  • attached the debugger and enable native exceptions to see there was no hidden crash, sometimes I get an exception in the .Net framework, but the app seems to continue.
  • try to reproduce in a small application, no success
A: 

This might be helpful:

http://stackoverflow.com/questions/75701/what-happens-to-global-variables-declared-in-a-dll

Are your globals declared inside a dll, or in your application's memory space?

sum1stolemyname
+2  A: 

The most common situation I encounter where this occurs is a program crash. In certain circumstances crashes can happen silently from an end user perspective. I would attach a debugger to the program, set it to break on all native exceptions and run the scenario.

JaredPar
already tried that, but thanks for the suggestion
eli
A: 

Calling theexit API often means that the application exits without calling destructors. I an not sure that VC does in this case.

Also try avoid using global objects. This is because you have little control over when and in what order the constructors and destructors are called. Rather convert the objects into pointers and initialise and destroy the pointers using the appropriate DllMain hooks. Since DllMain is an OS construct and not a language construct, it should prove more reliable in the case of normal exits.

doron
+2  A: 

It's possible that someone is calling TerminateProcess, which unlike ExitProcess does not notify DLLs of shutdown.

Hasturkun