Freeing memory error?

前端 未结 2 358
栀梦
栀梦 2020-12-21 12:49

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

相关标签:
2条回答
  • 2020-12-21 13:09

    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.

    0 讨论(0)
  • 2020-12-21 13:17

    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.)

    0 讨论(0)
提交回复
热议问题