cocos2dx中所有对象都继承于Ref,或者继承于 Ref和Clonable
Ref中就是维护了一个计数器,用于判断该继承于Ref的对象是否应该delete
class CC_DLL Ref { public: //计数加1 void retain(); //计数减1,如果为0,删除对象 void release(); //添加到对象池中,别忘了PoolManager(对象池管理器) 管理AutoreleasePool(对象池),AutoreleasePool管理Ref Ref* autorelease(); //得到当前的计数 unsigned int getReferenceCount() const; protected: //创建时计数设为1 Ref(); public: virtual ~Ref(); protected: /// count of references //计数变量 unsigned int _referenceCount; //友元类 friend class AutoreleasePool; #if CC_ENABLE_SCRIPT_BINDING public: /// object id, ScriptSupport need public _ID unsigned int _ID; /// Lua reference id int _luaID; #endif };
cocos2dx3.0 Ref,布布扣,bubuko.com
原文地址:http://blog.csdn.net/w18767104183/article/details/25876481