CComPtr 유형의 개체를 사용하고 있습니다. 하지만 메모리 누수 문제가 있습니다.CComPtr 및 참조 카운트
CComPtr<ID2D1Bitmap> bitmap = create_bitmap(bitmapSize);
auto n = count_ref((ID2D1Bitmap*)bitmap);
:
template<class Interface>
ULONG count_ref(Interface* pInterface) noexcept
{
if (pInterface)
{
pInterface->AddRef();
return pInterface->Release();
}
return 0;
}
그리고 : 특히, 나는 다음과 같은 코드가
ID2D1Bitmap* create_bitmap(const D2D1_SIZE_U& size)
{
ID2D1Bitmap* bitmap;
CreateBitmap(&bitmap);
return bitmap;
}
내가 1과 동일한 n
의 값을 기다리고 있었다를하지만, 실제로 동일 2. 내 CComPtr
의 참조 횟수가 1이 아닌 이유는 무엇입니까?
내 CComPtr
개체를 올바르게 사용하고 있습니까?
그리고 프로세스가 나는 다음과 같은 메모리 누수 얻을 종료 될 때 : 당신이 포인터에서 CComPtr를 구성 할 때
An interface [072B1F50] was created but not released. Use 'dps 072B1F20' to view its allocation stack.
Object type: ID2D1Bitmap
Device-dependent size: 1000 x 600
Device-independent size: 1000.00 x 600.00
Format: DXGI_FORMAT_B8G8R8A8_UNORM
Alpha mode: D2D1_ALPHA_MODE_PREMULTIPLIED
Outstanding reference count: 1
D2D DEBUG ERROR - Memory leaks detected.
CComPtr :: Attach()를 사용하여 인터페이스 포인터의 소유권을 가져옵니다. –