Bug in autorelease

Bug in autorelease
0.0 0


I have encountered strange behavior of autorelease. I might be wrong but this works correctly in objective-c reference counting model. But in cocos implementation it fails

Scenario (I am using new pool only to demonstrate behavior – it obviously happens without it but it’s harder to find):

//Create new autorelease pool

//Create dummy object. It's reference counter should be 1
CCObject * object = new CCObject();

//Mark current object as autorelease

//Mark object as autorelease again

//Retain - counter should be (and is) 2

//Drain my pool (that should decrement by 1)


The problem is in double autorelease. When I pop my newly allocated AutoreReleasePool it set’s to all children m_bManaged = false. That’s correct. But than m_pManagedObjectArray->removeAllObjects(); is called and on each item in this array is called release. That results in counter decrement by 2 and deallocation. That’s definitely not correct. Object should be deallocated in my last function but instead of that I am triing to access already empty object.


I am sorry, current implementation of Autorelease pool only supports one pool.
It is managed by engine, you should not create one by your self.


CCAutoreleasePool still cannot be “nested” and isn’t thread-safe now.