标签:
直接上代码
Ref::Ref() : _referenceCount(1) // when the Ref is created, the reference count of it is 1 { }
初始为1
Ref::~Ref() { #if CC_REF_LEAK_DETECTION if (_referenceCount != 0) // 没有异常使用的情况下 _referenceCount 为 0 untrackRef(this); #endif }
上面只是LEAK检测
void Ref::retain() { CCASSERT(_referenceCount > 0, "reference count should greater than 0"); ++_referenceCount; } void Ref::release() { CCASSERT(_referenceCount > 0, "reference count should greater than 0"); --_referenceCount; delete this; } }
留意到 delete this。
标签:
原文地址:http://www.cnblogs.com/d20062303732/p/4330704.html