![]() |
CloudBuilder C++ SDK
v3.0.0
Making social games is easy !
|
#include <CotCHelpers.h>
Public Member Functions | |
void | Retain () |
void | Release () |
CRefClass (const CRefClass &other) | |
CRefClass & | operator= (const CRefClass &other) |
Static Public Member Functions | |
template<class T > | |
static T * | Retain (T *t) |
template<class T > | |
static T * | Release (T *t) |
Public Attributes | |
unsigned | __ref_count |
Base class indicating a reference-counted object. The rules are as follow:
Once all the owners have called Release() (the original one which created it as well as all those which called Retain()) the object can be destroyed.
Technically, the object starts with a reference count of 1, calling Release() decrements the count, calling Retain() increments it. When reaching zero, the object is destroyed.
Example:
Note: you may also create CRefClass'es on the stack. In that case, the original creator shall not call Release() (other objects which have called Retain() may though, as they don't know how the variable was created). The following will work as expected:
An exception saying "Freeing an object that is still retained elsewhere" can be triggered if you delete an object without using Release(). This can also happen implicitly when using the stack, as in the following example:
In this example, the object A is destroyed by the compiler as we reach the end of the block, but it is still retained in B. This is why it is highly recommended not to create CRefClass'es on the stack except for local use.