我试图追踪内存泄漏。"但是,由于调用ReportLiveDeviceObjects
报告有0个引用
D3D11 WARNING: Live ID3D11Texture2D at 0x00000140D3FE44F0, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D]
D3D11 WARNING: Live ID3D11RenderTargetView at 0x00000140D3FCBB60, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #428: LIVE_RENDERTARGETVIEW]
D3D11 WARNING: Live ID3D11Texture2D at 0x00000140D3FE5BF0, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D]
D3D11 WARNING: Live ID3D11RenderTargetView at 0x00000140B8EDB000, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #428: LIVE_RENDERTARGETVIEW]
如您所见,ID3D11RenderTargetView
对象同时具有0个内部和外部引用。然而,它仍然是一个活的对象。什么可能导致这种情况发生?
为清楚起见,我通过SharpDX使用它,虽然这不会影响DirectX 11的调试输出。
答案 0 :(得分:3)
DirectX 11使用“延迟销毁”资源,因此通常如果您需要强制销毁,则需要// Remove any bound render target or depth/stencil buffer
ID3D11RenderTargetView* nullViews [] = { nullptr };
m_d3dContext->OMSetRenderTargets(_countof(nullViews), nullViews, nullptr);
// Destroy the views (which themselves hold the references to the resources)
m_renderTargetView.Reset();
m_depthStencilView.Reset();
// Flush the immediate context to force cleanup
m_d3dContext->Flush();
。例如,在Direct3D game templates中,您需要在调整大小之前完全取消绑定并销毁渲染目标:
{{1}}