What would cause an application to crash on subsequent start up when managed resources are not disposed?-Collection of common programming errors

I’m working on an application for a motion tracking device and have discovered some odd behavior that got me curious. The device SDK consists of three DLLs, one of them (the main referenced DLL being used in the application) non-native, and the other two native.

The application has three main actors, the Controller (connection between device and application), Listener (receives tracking information) and an endless stream of Frame objects (the data the Listener receives). All these items are disposable, in turn I believe they use unmanaged resources.

If I do not remove the listener from the controller and then dispose of the controller, the application will crash on subsequent startup. This behavior is sporadic, it might happened at the second, third or later startup.

Although I am making sure I am disposing the objects, I’m still very curious what logic or lack of logic can cause this type of behavior. Because I expect all objects to be disposed when an executable stops running.

Could the device drivers hold onto a reference? And what would be the best way to troubleshoot this? So the question is not how to dispose, but what would/could cause this, and why- and how can I Sherlock Holmes this.

More information:

  • No exceptions
  • Attaching a debugger doesn’t provide more information