释放通过D3D11CreateDevice()分配的资源 [英] Release resources allocated with D3D11CreateDevice()

查看:98
本文介绍了释放通过D3D11CreateDevice()分配的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短的问题:成功调用D3D11CreateDevice()之后,我得到了HRESULT.相关功能的最后:如何释放为此分配的资源?

Short question: after successfully calling D3D11CreateDevice(), I got back a HRESULT. At the very end of the related functionality: how do I release the resources allocated with this?

推荐答案

来自

From Managing Object Lifetimes Through Reference Counting, we can find a good explanation.

当对象不再存在时,必须对其进行释放,这一点很重要正在使用.困难在于确定什么时候合适取消分配对象.对于动态分配的COM对象,它由对象的客户端决定何时不再需要它们使用对象,尤其是可能位于其中的本地或远程对象由多个客户端同时使用.该对象必须等到所有客户在释放自己之前都已经完成了它.因为COM对象通过接口指针进行操作,并且可以由在不同进程或其他计算机上的对象,系统无法跟踪对象的客户.

It is important that an object be deallocated when it is no longer being used. The difficulty lies in determining when it is appropriate to deallocate an object. For COM objects, which are dynamically allocated, it is up to the clients of an object to decide when they no longer need to use the object—especially local or remote objects that might be in use by multiple clients at the same time. The object must wait until all clients are finished with it before freeing itself. Because COM objects are manipulated through interface pointers and can be used by objects in different processes or on other machines, the system cannot keep track of an object's clients.

COM的确定何时适当分配资源的方法对象是手动参考计数.每个对象都维护一个引用计数,以跟踪有多少个客户端连接到该客户端,即在任何客户端中,都有许多指向其任何接口的指针.

COM's method of determining when it is appropriate to deallocate an object is manual reference counting. Each object maintains a reference count that tracks how many clients are connected to it - that is, how many pointers exist to any of its interfaces in any client.

有关更多信息,请参见:管理参考计数的规则

For more information, see: Rules for Managing Reference Counts

在实现或使用引用计数的对象时,它可能会很有用应用人工参考计数,以确保对象稳定性在处理函数期间.在实施一种介面,您可能会呼叫有可能递减的函式您对一个对象的引用计数,导致该对象的过早释放对象和实施失败.一种避免这种情况的可靠方法是在方法的开头插入对AddRef的调用实施,并在调用之前将其与对Release的调用配对方法返回.

另一个可能对您有用的链接: D3D11从何处增加引用计数?

Another link that may be useful to you: D3D11 increased ref count from nowhere?

这篇关于释放通过D3D11CreateDevice()分配的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆