For example, i run in loop this code:
m_device->CreateBuffer(&index_buffer_desc, &index_data, &buffer);
Release(buffer);
where m_device is ID3D11Device and buffer is ID3D11Buffer
Nothing leaks – i create object and then destroy it.
If i attach it to pipeline, like this:
m_device->CreateBuffer(&index_buffer_desc, &index_data, &buffer);
m_device_context->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, 0);
Release(buffer);
than memory leaks starts.
MSDN says about IASetIndexBuffer that: “The method will not hold a reference to the interfaces passed in. For that reason, applications should be careful not to release an interface currently in use by the device.”
OK. I reset index buffer after attach:
m_device->CreateBuffer(&index_buffer_desc, &index_data, &buffer);
m_device_context->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, 0);
m_device_context->IASetIndexBuffer(NULL, DXGI_FORMAT_R32_UINT, 0);
Release(buffer);
But memory steal leaks.
What is the reason? Where this object still sits?
Really, i just restart this code and nothing happens, no leak. Nothing was changed. It was really strange behavior.
Before post this question a always try to use ID3D11DeviceContext::ClearState method, but memory steal leaks.
Anyway, now all fine.