Jump to content
  • Advertisement


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


Help:Memory Leak using CreateDIBSection( ) int Win98.

This topic is 5649 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()

    CSize sizeTotal;
    sizeTotal.cx = sizeTotal.cy = 100;
    SetScrollSizes(MM_TEXT, sizeTotal);

//Memery DC

    CDC *pDC = GetDC( );

    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 );
	MessageBox("bitmap failed");
    m_hOldBitmap = (HBITMAP)SelectObject( m_MemDC.m_hDC, m_hBitmap );


//OnDestroy( )

void CMapView::OnDestroy() 

    m_MemDC.SelectObject( m_hOldBitmap );
    m_MemDC.DeleteDC( );
    DeleteObject( m_hBitmap );
[edited by - mittens on May 2, 2003 12:28:11 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
i think the problem might be the "m_MemDC.SelectObject( m_hOldBitmap )" statement. you''re passing in a HBITMAP when you should be passing in a CBitmap* . if you change that to "SelectObject( m_MemDC.m_hDC, m_hOldBitmap )" it might clear up the problem.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!