Hi there,
I’m profiling my Cocos2DX game with Xcode and I’m getting severals leaks with cocos2d::CCMutableArraycocos2d::CCSpriteFrame* as Leaked Object.
These warnings come from my own AnimatedSprite class instances.
AnimatedSprite class extends CCSprite class and contains animations frames and a few functions in order to play and stop animations.
What I’m doing is basically this:
class EnemySprite : public AnimatedSprite
{
public:
EnemySprite()
{
CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( "enemy.png" );
initWithSpriteFrame( pFrame );
// animations -------------------------------------------------------------------------
CCSpriteFrameCache* pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
// stand animation ---------------------------------------------------------------------
CCSpriteFrame *standFrame0 = pCache->spriteFrameByName( "enemyStandAnim1.png" );
CCSpriteFrame *standFrame1 = pCache->spriteFrameByName( "enemyStandAnim2.png" );
CCSpriteFrame *standFrame2 = pCache->spriteFrameByName( "enemyStandAnim3.png" );
CCMutableArray< CCSpriteFrame* >* standAnimationFrames = new CCMutableArray< CCSpriteFrame* >();
standAnimationFrames->addObject( standFrame0 );
standAnimationFrames->addObject( standFrame1 );
standAnimationFrames->addObject( standFrame2 );
CCAnimation *standAnimation = CCAnimation::animationWithFrames( standAnimationFrames );
standAnimation->setDelay( 0.04f );
// walk animation -----------------------------------------------------------------------
CCSpriteFrame *walkFrame0= pCache->spriteFrameByName( "enemyWalkAnim1.png" );
CCSpriteFrame *walkFrame1 = pCache->spriteFrameByName( "enemyWalkAnim2.png" );
CCMutableArray< CCSpriteFrame* >* walkAnimationFrames = new CCMutableArray< CCSpriteFrame* >();
walkAnimationFrames->addObject( walkFrame0 );
walkAnimationFrames->addObject( walkFrame1 );
CCAnimation *walkAnimation = CCAnimation::animationWithFrames( walkAnimationFrames );
walkAnimation ->setDelay( 0.04f );
// push the animations ------------------------------------------------------------------
animations->addObject( standAnimation );
animations->addObject( walkAnimation );
}
virtual ~EnemySprite(){}
protected:
};
and these are AnimatedSprite class constructor and destructor:
AnimatedSprite::AnimatedSprite()
{
animations = new CCMutableArray< CCAnimation* >();
}
AnimatedSprite::~AnimatedSprite()
{
animations->release();
animations = NULL;
}
Am I doing this right? Is animations~~>release enough to free all animation resources?
Destructor is called, I’m sure about this. I’m not 100% sure if animations~~>release() also deallocates all objects contained inside the CCMutableArray.
I can’t figure it out why xCode’s profiler is popping out all these CCMutableArray leaks then…
Thanks in advance for your help!