Reputation: 20066
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.
Upvotes: 0
Views: 623
Reputation: 1059
[ 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];
Upvotes: 1
Reputation: 2300
If you allocate something into memory, you must deallocate it.
Node is a creation method that handles memory allocation with an autorelease pool.
Upvotes: 1