HDC memory leak (release HDC/ delete hdc)

I'm having trouble with this HDC memory leak. Could you guys check if I'm releasing/deleting HDC correctly?

Thank you!

BITMAP bm; HBITMAP hbmap; HBITMAP hBitmapOld; BITMAPINFO bmi; HDC hdcShot; 

...

if (!TakeScreenshot(GameWindow, bm, hbmap, bmi, hdcShot, hBitmapOld, appWnd))                 break;          HBITMAP hbmapNew = CreateCompatibleBitmap(hdcShot, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);          HDC hdcShotNew = CreateCompatibleDC(hdcShot);          HBITMAP OldBmp = (HBITMAP)SelectObject(hdcShotNew, hbmapNew);           BitBlt(hdcShotNew, 0, 0, rcWindow.right - rcWindow.left/*Window WIDTH*/, rcWindow.bottom - rcWindow.top/*Window HEIGHT*/             , hdcShot, 0, 0, SRCCOPY);           pPixels = new RGBQUAD[bm.bmWidth * bm.bmHeight];         if (!pPixels) return false;          SelectObject(hdcShotNew, OldBmp);           if (!GetDIBits(hdcShotNew, hbmapNew, 0, bm.bmHeight, pPixels, &bmi, DIB_RGB_COLORS))         {             ReleaseDC(appWnd, hdcShot);             delete[] pPixels;              return false;         }             ScanContents scanContentsMain(bm, rcWindow, pPixels);          ScanBMPHorizontal(&scanContentsMain);             //free memory         free(pPixels);         SelectObject(hdcShot, hBitmapOld);                 DeleteObject(hbmap);                 DeleteDC(hdcShot);                 DeleteObject(hbmapNew);                 DeleteObject(OldBmp);                 DeleteDC(hdcShotNew); 

I checked with deleakers and found out that I'm struggling with HDC leak. I'm not sure what I've done wrong.

Replay

Category: memory leaks Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.215 (s). 12 q(s)