azamsharp
azamsharp

Reputation: 20066

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.

Upvotes: 0

Views: 623

Answers (3)

mattblessed
mattblessed

Reputation: 801

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

Upvotes: 0

Srinivas
Srinivas

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

Bongeh
Bongeh

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

Related Questions