C++ release retain代码

 

class CC_DLL CCObject : public CCCopying
{
protected:
	// object id
    unsigned int		m_uID;
	// count of refrence
	unsigned int		m_uReference;
	// is the object autoreleased
	bool		m_bManaged;		
public:
	CCObject(void);
	virtual ~CCObject(void);
    
	virtual void release(void);
	virtual void retain(void);
	CCObject* autorelease(void);
	CCObject* copy(void);
	bool isSingleRefrence(void);
	unsigned int retainCount(void);
	bool isEqual(const CCObject* pObject);

	friend class CCAutoreleasePool;
};

 

 

void CCObject::release(void)
{
	assert(m_uReference > 0);
	--m_uReference;

	if (m_uReference == 0)
	{
		delete this;
	}
}

void CCObject::retain(void)
{
	assert(m_uReference > 0);

	++m_uReference;
}

 

你可能感兴趣的:(C++)