iosobjective-ccocos2d-iphoneccparticlesystem

CCParticleSystemQuad not getting deallocated when added to a moving sprite


I am trying to add a particle trail effect in cocos2d, I managed to do it by adding CCParticleSystemQuad emitter as a child to the moving sprite. But I am observing that this emitter is not getting deallocated eventually.

if I add this emitter to same sprite, but keep it still and dont move at all, emitter does get deallocated.

I cant figure out why this is happening..

code is somewhat like this..

CCParticleSystemQuad *emitter = [[[CCParticleSystemQuad alloc] initWithFile:@"myEffect.plist"] autorelease];
emitter.positionType = kCCPositionTypeFree;
emitter.autoRemoveOnFinish = YES;
[movingSprite addChild:emitter z:movingSprite.zOrder + 1000];

Solution

  • Make sure you called [emitter removeFromParentAndCleanup:YES];

    Here is one of my similar question

    Find out where object is retained, follow Morion's answer in above thread.

    Quick Solution:

    CCParticleSystemQuad *emitter = [CCParticleSystemQuad particleWithFile:@"myEffect.plist"];
    emitter.positionType = kCCPositionTypeFree;
    emitter.autoRemoveOnFinish = YES;
    [movingSprite addChild:emitter z:movingSprite.zOrder + 1000];
    
    //To remove
    [emitter stopSystem];
    [emitter removeFromParentAndCleanup:YES];