GDI 绘图 内存泄漏问题

GDI绘图


在窗体上绘图,必要用到双缓存的技术,而这又离不开两个函数:CreateCompatibleDC与CreateCompatibleBitmap


如下代码:

CDC* pMem=new CDC;    
	CBitmap* pBmp=new CBitmap; 
	CBitmap* pOldBmp; 
	CDC* pDC=GetDC();  
	pMem->CreateCompatibleDC(pDC);  
	pBmp->CreateCompatibleBitmap(pDC, m_chartRect.Width(), m_chartRect.Height()); 
	pOldBmp=pMem->SelectObject(pBmp);
……
pMem->FillRect(&r, &myBackground);
……
	pDC->BitBlt(m_chartRect.left,m_chartRect.top,m_chartRect.Width(),m_chartRect.Height(),pMem,0,0,SRCCOPY); 
	pMem->SelectObject(pOldBmp); 
	pBmp->DeleteObject();
	pMem->DeleteDC();
————————————————
pBmp->DeleteObject();   
  pMemDC->DeleteDC(); //这两句话并不是完全把资源释放

还需要加上以下三句
delete pBmp;
delete pMem;
Release(pDC);
 
  

你可能感兴趣的:(c++,图形,内存泄漏)