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?
Or am I not seeing something?
*note I’m talking about this from the concept of the IDirect3DTexture9::Release() function
Your theory is true. COM memory management is based on reference counting. The
Releasemethod ofIUnknowninterface 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.Thus, you should only call
Releasefor eachAddRefyou had previously called.