使用 D3D,我是否需要在退出进程之前调用release?
我正在学习的 direct3d 教程是这样说的:
“......基本上,如果您创建 Direct3D,但从不关闭它,它将继续在计算机后台运行,直到您下次重新启动,即使是在程序本身之后不好。如果你的游戏中有很多资源,那么就更糟糕了。” (链接)
我真的不相信本教程所说的,退出进程后,资源仍然会挂起...
就像我的程序崩溃或者我在调试时只是按停止键..资源是否仍然挂起?对于其他使用 directx 的游戏,我经常通过终止进程来关闭它们。
如果我退出进程并且不调用 device->Release,资源是否可以释放给操作系统?
The tutorial that i'm taking for direct3d says this:
"... 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." (link)
I really don't believe what this tutorial says, that the resources will still hang about after you exit the process...
Like if my program crashes or i simply press stop while debugging.. are the resources still hanging around? And other games which use directx, i often close them by killing the process.
Will the resources be free to the operating system if i exit my process and don't call device->Release?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单地说,不。那不是真的。当进程终止时,所有 DirectX 资源都将被释放,并且不会泄漏 GPU 或系统内存。
Simply put, no. That is not true. When your process terminates, all your DirectX resources will be freed and no GPU or system memory will be leaked.
虽然与进程相关的资源(例如内存、线程、句柄等)确实会被回收,但回想一下,D3D 也在利用视频硬件上的内存和资源。根据您的具体实现,未能通知 D3D 您正在关闭可能也不会在进程退出时清除所有这些内容。
我发现使用托管 DX9 接口的软件中出现了一些非常有趣的渲染伪影,这些伪影在 EvictManagedResources 已进行调用。这些工件发生在自动化测试套件中,是的 - 它们在同一进程的单独调用之间持续存在(作为显示/帧缓冲区上的小矩形垃圾)。
正确编码的应用程序仍然可以对内部异常和/或进程终止请求(WM_QUERYENDSESSION 等)做出适当的反应并执行此清理。
While it's true that process-related resources, such as memory, threads, handles, etc. will be reclaimed, recall that D3D is also utilizing memory and resources on the video hardware. Depending on your specific implementation, failing to inform D3D that you are shutting down can and will not clean all of these up on a process exit.
I have seen some very interesting rendering artifacts occur in software using the Managed DX9 interface that failed to clean up until the EvictManagedResources call was made. These artifacts occurred in an automated test suite, and yes - they persisted between separate invocations of the same process (as small rectangles of garbage on the display/framebuffer).
A properly coded app can still react appropriately to internal exceptions and/or process termination request (WM_QUERYENDSESSION, etc.) and perform this cleanup.