Handmade Network»Forums
Leonardo
21 posts
Does Window frees all the Direct3D resources on exit if I don't call ->Release() for each one of them?
Edited by Leonardo on
Like it happens for memory or file handles, does Windows also frees averything releated to Direct3D or COM in general? Or I must call ->Release() for everything that I've created before closing the program?

There is a question on Stack Overflow talking about that. They say that Windows always will free everything.
https://stackoverflow.com/questio...-release-before-i-exit-my-process

But in this tutorial, they say it won't, and everything will keep in memory even after the program has closed.
http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-1

From this tutorial:
Why? Well, let's say it would be a bad thing to do otherwise. Basically, if you create Direct3D, but never close it, it will just keep on running in the background of the computer until your next reboot, even after the program itself closes. Bad. Especially bad if you have a lot of resources in your game. Releasing these two interfaces let's everything off the hook and allows Windows to take back it's memory.
Mārtiņš Možeiko
2559 posts / 2 projects
Does Window frees all the Direct3D resources on exit if I don't call ->Release() for each one of them?
Edited by Mārtiņš Možeiko on
Yes, Windows will release all resources when process exits. This includes any file and other handles (sockets, thread, event, ..), memory allocations, gpu resources & other resources. Does not matter whether it is D3D or OpenGL or Vulkan resource. Everything will be cleaned up.

That quote is completely wrong.

Easy way to understand why this happens is if you think what happens during debugging - like you are running your code in debugger, program crashes or you stop debugging to change something and run again. If in these cases nothing would get deallocated or freed or Released, then debugging programs would become impossible. But obviously that does not happen, as you can easily debug & crash your programs thousand times a day and your OS does not run out of memory. Resources are released regardless of how your application exits - normally, or being terminated via task manager, or stopped via debugger, or just because of crash.
Leonardo
21 posts
Does Window frees all the Direct3D resources on exit if I don't call ->Release() for each one of them?
I see!

Thank you Mārtiņš.