Advertisement Jump to content


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


Win32 Objects : Releasing / Deleting / When / Where / Why?

This topic is 5485 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''m a litle confused on when you delete an object and when you release an object and things, with win32. In the Win32 tutorial at GAmeTutorials, during the unloading, you do something like this:
	// We made a backbuffer, clean it all up.

		// Select back the original surface.

		SelectObject(m_hBackDC, m_hOldBITMAP);

		// Delete Our Backbuffer.


	// If we have a DC, release it.

		ReleaseDC(m_hWnd, m_hPrimaryDC);
Why do you release the Primary Buffer DC but delete the Back Buffer DC? Also, with that SelectObject(m_hBackDC, m_hOldBITMAP), why do you delete the m_hBackBITMAP but not the m_hOldBITMAP? I''m a little confused here, and is bollocks for explaining anything.

Share this post

Link to post
Share on other sites
You call ReleaseDC() when you got the device context by calling GetDC() or GetWindowDC().

You call DeleteDC() when you got the device context by calling CreateDC().

They probably used DeleteObject() on m_hBackBITMAP because they used CreateBitmap() (or one of its relatives) to create it.

The SelectObject() call is because before you delete a device context you should restore it''s original handles. In this case m_hOldBITMAP was probably the original bitmap object in the device context.

Share this post

Link to post
Share on other sites
If you are unsure if you should release or if you should delete simply check the MSDN documentation of the function you used to create the resource. It will tell you how to clean that resource up.

The reason you dont delete m_hOldBITMAP is because you didn''t create it. It was given to you and you must put it back.

Colin Jeanne | Invader''s Realm

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!