I'm experiencing memory leaks while running 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, such as this but I couldn't find the problem. Any help would be appreciated.
DeleteDC, ReleaseDC return value was checked to be true (no errors).
Thanks, Tal.
Solved. The problem was hBmp wasn't correctly initialized, so there was a crash at the SelectObject - no error, just the function exited, skipping the "//do something" and the releases part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With