【cocos2dx】Ref 到底是什么鬼?



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
};

以上转自:http://blog.csdn.net/w18767104183/article/details/25876481




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值