Search code examples
c++memory-leaksdirect3ddevice-driver

What happens when you leak a "device" and "device context" - specifically d3d?


I'm a little unclear exactly how these objects function that form bridges between software and hardware. Are they pretty much just software objects that get destroyed if you leak them onto the heap when you terminate the process? Or is there something more to it?

The reason I ask is I forgot to have my initialization routine change its statemachine and hence switch routines resulting in it creating as many "DeviceContexts" and "Devices" as it possibly could and reassigning them to the same pointers (via d3d11createdevice) before I caught my memory leaking at about 2GB.

Then it occurred to me that I really have no clue what it means to fail to release these objects. Is there a hardware component to them that I should be concerned about if these objects were to be leaked such that I need to reset my computer? Or does terminating the process pretty much clean up the mess?

I cold reset my computer regardless just to be sure. But it would be nice to know exactly what happens when you are using low level interfaces like this and you fail to properly destroy/release them.


Solution

  • The operating system will clean up all those device contexts when your program terminates. Otherwise a misbehaved program could bring the system to a standstill.

    Your other concern (expressed in a comment) about damaging hardware shouldn't be possible either. If it was a malicious program could wreak all sorts of havoc. You may be possible to damage hardware by directly accessing it, but that sort of access is what the driver (and the device context, which sits between your program and the driver) is for.