Archived

This topic is now archived and is closed to further replies.

Help:Memory Leak using CreateDIBSection( ) int Win98.

This topic is 5337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I found memory leak when using CreateDIBSection( ).The detail is that after starting my application and closing my application several times,The Bitmap couldn''t be successfully created when I restarted my application.The code is like the following.Thanks!(The Application is based on MFC,SDI) //the variable definition CDC m_MemDC; HBITMAP m_hBitmap; HBITMAP m_hOldBitmap; void *m_pBits; //OnInitialUpdate( ) void CMapView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize sizeTotal; sizeTotal.cx = sizeTotal.cy = 100; SetScrollSizes(MM_TEXT, sizeTotal); //Memery DC CDC *pDC = GetDC( ); m_MemDC.CreateCompatibleDC(pDC); BITMAPINFOHEADER bih; ZeroMemory( &bih, sizeof(bih) ); bih.biBitCount = 24; bih.biClrImportant = 0; bih.biClrUsed = 0; bih.biCompression = 0; bih.biHeight = 5000; bih.biPlanes = 1; bih.biSize = sizeof(bih); bih.biWidth = 5000; bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; m_hBitmap = ::CreateDIBSection( pDC->m_hDC, (BITMAPINFO*)&bih, DIB_RGB_COLORS, &m_pBits, NULL, 0 ); if(m_hBitmap==NULL) MessageBox("bitmap failed"); m_hOldBitmap = (HBITMAP)SelectObject( m_MemDC.m_hDC, m_hBitmap ); ReleaseDC(pDC); } //OnDestroy( ) void CMapView::OnDestroy() { CScrollView::OnDestroy(); m_MemDC.SelectObject( m_hOldBitmap ); m_MemDC.DeleteDC( ); DeleteObject( m_hBitmap ); }

Share this post


Link to post
Share on other sites