Microsoft对象,Release()函数返回值? [英] Microsoft objects, the Release() functions return value?

查看:454
本文介绍了Microsoft对象,Release()函数返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,因为我在MSDN上找不到这个。我发现 Release()函数存在于各种COM对象中,我显然应该用它来删除指针。但我不知道它返回什么?我以前认为它会返回仍然存在的对象剩余引用的数量,因此类似:

I'm curious because I couldn't find out about this on MSDN. I've found the Release() function is present in various COM objects which I'm obviously supposed to use for deleting pointers. But I'm not sure what does it return exactly? I used to think it would return the number of references which still exist to the object remaining, therefore something like:

while( pointer->Release() > 0 );

显然会释放对该指针的所有引用?

Would obviously release all references to that pointer?

或者我没有看到什么?

*注意,我是从 IDirect3DTexture9 :: Release function

*note I'm talking about this from the concept of the IDirect3DTexture9::Release() function

推荐答案

COM内存管理基于引用计数。接口的 Release 方法将递减引用计数并返回。该函数不会释放引用。它不知道谁持有参考。它只是减少引用计数,直到它达到零,然后对象将被销毁。

Your theory is true. COM memory management is based on reference counting. The Release method of IUnknown interface will decrement the reference count and return it. That function will not release references. It doesn't know who holds the reference. It just decrements the reference count until it reaches zero and then the object will be destructed. It's dangerous as others might still hold a reference to it that will become invalid after object's destruction.

因此,你应该只调用 Release 每个 AddRef 您以前呼叫过。

Thus, you should only call Release for each AddRef you had previously called.

这篇关于Microsoft对象,Release()函数返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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