mirror of https://github.com/axmolengine/axmol.git
Merge pull request #1427 from dumganhar/iss1494-autorelease
fixed #1494: Missing removing auto-release object from AutoReleasePool if invoking 'autorelease' method more times.
This commit is contained in:
commit
b291fff32e
|
@ -41,18 +41,19 @@ CCAutoreleasePool::~CCAutoreleasePool(void)
|
||||||
|
|
||||||
void CCAutoreleasePool::addObject(CCObject* pObject)
|
void CCAutoreleasePool::addObject(CCObject* pObject)
|
||||||
{
|
{
|
||||||
CCAssert(false == pObject->m_bManaged, "this object is already in autorelese pool");
|
|
||||||
|
|
||||||
m_pManagedObjectArray->addObject(pObject);
|
m_pManagedObjectArray->addObject(pObject);
|
||||||
|
|
||||||
CCAssert(pObject->m_uReference > 1, "reference count should be greater than 1");
|
CCAssert(pObject->m_uReference > 1, "reference count should be greater than 1");
|
||||||
|
++(pObject->m_uAutoReleaseCount);
|
||||||
pObject->release(); // no ref count, in this case autorelease pool added.
|
pObject->release(); // no ref count, in this case autorelease pool added.
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAutoreleasePool::removeObject(CCObject* pObject)
|
void CCAutoreleasePool::removeObject(CCObject* pObject)
|
||||||
{
|
{
|
||||||
m_pManagedObjectArray->removeObject(pObject, false);
|
for (int i = 0; i < pObject->m_uAutoReleaseCount; ++i)
|
||||||
|
{
|
||||||
|
m_pManagedObjectArray->removeObject(pObject, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAutoreleasePool::clear()
|
void CCAutoreleasePool::clear()
|
||||||
|
@ -70,7 +71,7 @@ void CCAutoreleasePool::clear()
|
||||||
if(!pObj)
|
if(!pObj)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pObj->m_bManaged = false;
|
--(pObj->m_uAutoReleaseCount);
|
||||||
//(*it)->release();
|
//(*it)->release();
|
||||||
//delete (*it);
|
//delete (*it);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
|
|
@ -38,7 +38,7 @@ CCObject* CCCopying::copyWithZone(CCZone *pZone)
|
||||||
}
|
}
|
||||||
|
|
||||||
CCObject::CCObject(void)
|
CCObject::CCObject(void)
|
||||||
:m_bManaged(false)
|
:m_uAutoReleaseCount(0)
|
||||||
,m_uReference(1) // when the object is created, the reference count of it is 1
|
,m_uReference(1) // when the object is created, the reference count of it is 1
|
||||||
,m_nLuaID(0)
|
,m_nLuaID(0)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ CCObject::~CCObject(void)
|
||||||
{
|
{
|
||||||
// if the object is managed, we should remove it
|
// if the object is managed, we should remove it
|
||||||
// from pool manager
|
// from pool manager
|
||||||
if (m_bManaged)
|
if (m_uAutoReleaseCount > 0)
|
||||||
{
|
{
|
||||||
CCPoolManager::sharedPoolManager()->removeObject(this);
|
CCPoolManager::sharedPoolManager()->removeObject(this);
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,6 @@ void CCObject::retain(void)
|
||||||
CCObject* CCObject::autorelease(void)
|
CCObject* CCObject::autorelease(void)
|
||||||
{
|
{
|
||||||
CCPoolManager::sharedPoolManager()->addObject(this);
|
CCPoolManager::sharedPoolManager()->addObject(this);
|
||||||
|
|
||||||
m_bManaged = true;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
// count of references
|
// count of references
|
||||||
unsigned int m_uReference;
|
unsigned int m_uReference;
|
||||||
// is the object autoreleased
|
// count of autorelease
|
||||||
bool m_bManaged;
|
unsigned int m_uAutoReleaseCount;
|
||||||
public:
|
public:
|
||||||
CCObject(void);
|
CCObject(void);
|
||||||
virtual ~CCObject(void);
|
virtual ~CCObject(void);
|
||||||
|
|
Loading…
Reference in New Issue