Skip to main content
gamedev.net
🔒 Locked

Basic question about releasing interfaces

Started by lack o comments Oct 9, 2004 at 8:22 PM 0 replies 250+ views
Original Post
lack o comments
lack o comments
This question has been on my mind a long time, and I don't really know enough about COM or Windows to figure it out myself. Is it safe to release an interface (particularly, one that uses the instance of the app) after WinMain has been exited. For instance, if I wrapped IDirectDraw in a class and its release method was called in a global destructor. My guess has always been, no. But I'm really not sure and just a little curious. Thanks in advance.
S1CA
S1CA

Personally I'd advise always making sure final releases are done before the end of WinMain.

If the interface has been passed a window handle (such as the focus window used for creating D3D devices or the one used for SetCooperativeLevel() calls), then the final release should happen before the window is destroyed - which usually implies it should happen before the end of WinMain


Having said that, global destructors are handled very soon after the end of WinMain anyway under MSVC - but it's considered messy/bad practice because exactly where they get called and the state of things like the C runtime library isn't guaranteed across different compilers and even different revisions of the same compiler.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.