开发者

Why is my CCParticleExplosion Leaking Memory?

I have the following code:

CCParticleExplosion *explosion = [[CCParticleExplosion alloc] init];
    explosion.texture = [[CCTextureCache sharedTextureCache] addImage:@"chick.png"];
    explosion.position = egg.position;
   开发者_运维问答 [explosion setAutoRemoveOnFinish:YES];
    [explosion setTotalParticles:10];
    [self.layer addChild:explosion];

I thought that setAutoRemoveOnFinish will automatically remove the explosion node from the layer and release it. But the xCode instruments says that CCParticleExplosion is leaking memory!

UPDATE 1:

Solved the problem by using CCParticleExplosion node instead of alloc.


If you allocate something into memory, you must deallocate it.

Node is a creation method that handles memory allocation with an autorelease pool.


[ explosion autorelease];

add above line to your code.

CCParticleExplosion *explosion = [[CCParticleExplosion alloc] init];
    explosion.texture = [[CCTextureCache sharedTextureCache] addImage:@"chick.png"];
    explosion.position = egg.position;
    [explosion setAutoRemoveOnFinish:YES];
    [explosion setTotalParticles:10];
    [self.layer addChild:explosion];
    [ explosion autorelease];


just use [explosion release]; after you're done using it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜