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
精彩评论