转自:http://blog.csdn.net/w18767104183/article/details/25876481@H_301_1@
@H_301_1@
@H_301_1@
cocos2dx中所有对象都继承于Ref,或者继承于 Ref和Clonable
Ref中就是维护了一个计数器,用于判断该继承于Ref的对象是否应该delete@H_301_1@
- classCC_DLLRef
- {
- public:
- //计数加1
- @H_301_52@voidretain();
- //计数减1,如果为0,删除对象
- voidrelease();
- //添加到对象池中,别忘了PoolManager(对象池管理器)管理AutoreleasePool(对象池),AutoreleasePool管理Ref
- Ref*autorelease();
- //得到当前的计数
- unsignedintgetReferenceCount()@H_301_52@const;
- protected:
- //创建时计数设为1
- Ref();
- public:
- virtual~Ref();
- protected:
- ///countofreferences
- //计数变量
- int_referenceCount;
- //友元类
- friend@H_301_52@classAutoreleasePool;
- #ifCC_ENABLE_SCRIPT_BINDING
- ///objectid,ScriptSupportneedpublic_ID
- int_ID;
- ///Luareferenceid
- int_luaID;
- #endif