GDI leak problem

I am experiencing memory leaks when I run the following GDI code:

HDC hdcScreen = GetDC(NULL);
HDC hdcMem = CreateCompatibleDC(hdcScreen); 
HBITMAP hbmpOld = (HBITMAP) SelectObject(hdcMem, hBmp); // apparently here is the leak 

// do something

SelectObject(hdcMem, hbmpOld); //placing the old object back. The return object is handled elseware
DeleteDC(hdcMem);  // after CreateCompatibleDC
ReleaseDC(NULL, hdcScreen); // after GetDC

I already looked at similar threads like this one , but I could not find the problem. Any help would be appreciated.

DeleteDC, the return value of ReleaseDC was checked as true (no errors).

Thanks, Tal.

+3
source share
2 answers

solved. The problem was that hBmp was not properly initialized, so there was a failure in SelectObject - there is no error, only the function exited, skipping "// do something" and part of the release.

+4
source

NirSoft GDIView, GDI ( ) , , GDIView, , , , .

0

Source: https://habr.com/ru/post/1776212/


All Articles