未释放引用为0的DirectX11 COM对象

未释放引用为0的DirectX11 COM对象,com,directx-11,sharpdx,Com,Directx 11,Sharpdx,我正试图追踪一个“内存泄漏”。然而,它看起来不像是真正的内存泄漏,因为调用ReportLiveDeviceObjects报告有0个引用 D3D11 WARNING: Live ID3D11Texture2D at 0x00000140D3FE44F0, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D] D3D11 WARNING: Live ID3D11RenderTargetView at 0x000

我正试图追踪一个“内存泄漏”。然而,它看起来不像是真正的内存泄漏,因为调用
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的调试输出

相应问题:

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(); 

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(); 

这正是问题所在。我正在调用flush,但是在处理渲染目标之前而不是之后。这正是问题所在。我正在调用flush,但在处理渲染目标之前而不是之后。