For testing purposes, I put the code into a for loop which creates and releases one thousand Direct2D devices but it never free up the allocated memory:
for (UINT i = 0; i < 1000; i++) {
hr = m_lpD2DFactory->CreateDevice(lpDxgiDevice, &m_lpD2DDevice);
m_lpD2DDevice->Release();
}
Execution of the code above holds around 500MB of memory. Seems like releasing the device has no effect.
I appreciate any help.
Update
I have found out that if I uncomment rest of my code which leads to a pair of calls to ID2DRenderTarget::BeginDraw and ID2DRenderTarget::EndDraw using the created device, the Release
method works as expected. It is still strange and could be problem if somehow my code does not lead to those calls.
hr = m_lpD2DFactory->CreateDevice(lpDxgiDevice, &m_lpD2DDevice);
...
lpRenderTarget->BeginDraw();
lpRenderTarget->EndDraw();
...
m_lpD2DDevice->Release();