mirror of https://github.com/axmolengine/axmol.git
fixed #1494: Missing removing auto-release object from AutoReleasePool if invoking 'autorelease' method more times.
This commit is contained in:
parent
da4456ffee
commit
54b4c690d1
|
@ -41,8 +41,6 @@ CCAutoreleasePool::~CCAutoreleasePool(void)
|
|||
|
||||
void CCAutoreleasePool::addObject(CCObject* pObject)
|
||||
{
|
||||
CCAssert(false == pObject->m_bManaged, "this object is already in autorelese pool");
|
||||
|
||||
m_pManagedObjectArray->addObject(pObject);
|
||||
|
||||
CCAssert(pObject->m_uReference > 1, "reference count should be greater than 1");
|
||||
|
@ -70,7 +68,7 @@ void CCAutoreleasePool::clear()
|
|||
if(!pObj)
|
||||
break;
|
||||
|
||||
pObj->m_bManaged = false;
|
||||
--(pObj->m_uAutoReleaseCount);
|
||||
//(*it)->release();
|
||||
//delete (*it);
|
||||
#ifdef _DEBUG
|
||||
|
|
|
@ -38,7 +38,7 @@ CCObject* CCCopying::copyWithZone(CCZone *pZone)
|
|||
}
|
||||
|
||||
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_nLuaID(0)
|
||||
{
|
||||
|
@ -51,9 +51,12 @@ CCObject::~CCObject(void)
|
|||
{
|
||||
// if the object is managed, we should remove it
|
||||
// from pool manager
|
||||
if (m_bManaged)
|
||||
if (m_uAutoReleaseCount > 0)
|
||||
{
|
||||
CCPoolManager::sharedPoolManager()->removeObject(this);
|
||||
for (int i = 0; i < m_uAutoReleaseCount; ++i)
|
||||
{
|
||||
CCPoolManager::sharedPoolManager()->removeObject(this);
|
||||
}
|
||||
}
|
||||
|
||||
// if the object is referenced by Lua engine, remove it
|
||||
|
@ -98,7 +101,7 @@ CCObject* CCObject::autorelease(void)
|
|||
{
|
||||
CCPoolManager::sharedPoolManager()->addObject(this);
|
||||
|
||||
m_bManaged = true;
|
||||
++m_uAutoReleaseCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ public:
|
|||
protected:
|
||||
// count of references
|
||||
unsigned int m_uReference;
|
||||
// is the object autoreleased
|
||||
bool m_bManaged;
|
||||
// count of autorelease
|
||||
unsigned int m_uAutoReleaseCount;
|
||||
public:
|
||||
CCObject(void);
|
||||
virtual ~CCObject(void);
|
||||
|
|
Loading…
Reference in New Issue