1
\$\begingroup\$

I have a memory issue after disposing all my D3D objects and lastly disposing the device. I want to free all memory and, depending on user interaction, creating a new device, but removing all memory footprint of the old device.

I traced down some Disposing issues I had to only have this left, right at the line at disposing the device:

enter image description here

I get this by calling:

mDevice.QueryInterface<DeviceDebug>().ReportLiveDeviceObjects(ReportingLevel.Summary)

I understand that that the DeviceDebug interface I receive to get this debug information increases the Refcount of the ID3D11Device by +1. So it should be 2 references left.

Now I wonder if I need to track down this last reference (the 2nd) in order to get the device fully released after I call .Dispose(). Or if this is a internal refernece that is handled for me.

The issue is, that I don't know how to check for remainding objects after the device disposing. I get no warnings about active objects in output anymore, them I fixed already.

My memory grows linearly by about ~15MB each creation and destruction of my window (not closing the application, just the part that needs a device).

Any help appreciated!

\$\endgroup\$
1
\$\begingroup\$

You probably still have objects bound to the pipeline (via a context->Set call) at the time you perform the final dispose. In D3D11 binding an object will cause it's reference count to be incremented, meaning that there are still references to those objects, meaning that the objects will be leaked.

One way to resolve this is to explicitly set all state objects, shaders, shader resources, buffers, rendertargets, etc to NULL before disposing, which will clear the reference counts and allow the dispose to happen clearly.

The other, more reliable, way is to make a call to ID3D11DeviceContext::ClearState before disposing. This will also release all outstanding references, and is more suitable for doing a full shutdown of video, where the more nuclear option is exactly what you want.

\$\endgroup\$
2
  • \$\begingroup\$ Yes I did a ClearState call already in my code to get exactly that. I think I am hunting a ghost here thought, I shouldn't analyze my memory in debug mode either I think. I have different behavior in release mode. I accept your answer, thank you ! \$\endgroup\$ – Hexa Jan 22 '18 at 7:23
  • \$\begingroup\$ I queried this on the Sharpdx Git hub issues, the response was that you may be adding a Com reference just by querying the object reference. Which I found confusing, I was though inspecting the object and its members. \$\endgroup\$ – ErnieDingo Jan 28 '18 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.