I need to free the bitpointer
, because this function is executed multiple times and memory usage is growing for a reason I don\'t understand and it crashes afte
In SelectObject, save the returned value: HGDIOBJ save = SelectObject(hdcTemp, hBitmap2);
Then before ReleaseDC, delete the DIB DeleteObject( SelectObject(hdcTemp, save) );
Otherwise, you create bitmaps and don't delete them.
If you read the documentation you'll see that you shouldn't be allocating memory for bitPointer
, CreateDIBSection
does that for you. You need to use DeleteObject
to free hBitmap2
.
The crash occurs because the value of bitPointer
youi are freeing is not the one that you allocated. (And the memory you allocated is leaked.)