我注意到使用任务管理器,以下代码中存在 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);
R M