Sign in to follow this  

Basic question about releasing interfaces

This topic is 4813 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

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

This topic is 4813 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this