我注意到使用任务管理器后发现以下代码存在GDI泄漏。每次执行此代码的进程中的GDI对象计数增加1,但我似乎找不到问题所在。
任何帮助都将不胜感激。
任何帮助都将不胜感激。
// create new DC based on current
HDC hDC = CreateCompatibleDC(GetDC());
// select a bitmap into the new DC and keep the old one
HGDIOBJ hOldObj = SelectObject (hDC,hBM);
// do somthing here --> 100% no leak here
SomeFunction (hDC);
// select the old object back from whence it came and delete whats returned
DeleteObject (SelectObject (hDC,hOldObj));
// delete the DC
DeleteDC(hDC);
// delete the tmp object
DeleteObject (hOldObj);
RM
DeleteObject(hOldObj)
。那不是你的对象需要清理。你没创建它,所以不要删除它。 - Adrian McCarthy