CCParticleSystemQuand not dealloced

65 Views Asked by At

I want to do a very simple thing but it's not working. I want to add some CCParticleSystemQuad in an NSMutableArray and delete them. Here is what I do :

int cpt = 0;
NSMutableArray *myArray = [[NSMutableArray alloc] init];
for (cpt = 0; cpt < 10; cpt++) {
    part = [CCParticleSystemQuad particleWithFile:@"whiteExplosion.plist"];
    [myArray addObject:part];
}

NSLog(@"state of myArray : %@", myArray);

int cont = 0
for (cont = 0; cont < 10; cont++) {
    [myArray removeLastObject:cont];
}

NSLog(@"state of myArray : %@", myArray);

When I NSLog the first time I have this :

state of myArray : (
    "<CCParticleSystemQuad = 0x91ee380 | Tag = -1>",
    "<CCParticleSystemQuad = 0x84aca20 | Tag = -1>",
    "<CCParticleSystemQuad = 0x125136c0 | Tag = -1>",
    "<CCParticleSystemQuad = 0x125b0fc0 | Tag = -1>",
    "<CCParticleSystemQuad = 0x1250d480 | Tag = -1>",
    "<CCParticleSystemQuad = 0x1250fa50 | Tag = -1>",
    "<CCParticleSystemQuad = 0x9108840 | Tag = -1>",
    "<CCParticleSystemQuad = 0x9152b70 | Tag = -1>",
    "<CCParticleSystemQuad = 0x914fb80 | Tag = -1>",
    "<CCParticleSystemQuad = 0x9135470 | Tag = -1>"
)

The second time I have this :

state of myArray : (
)

So, as you can see my CCParticleSystemQuad have been removed. But, when I check in Instruments (allocations) they are still living (I have 20 still living [CCParticleSystemQuad allocMemory]) and still using memory for nothing. What am I missing ? BTW I use ARC. I tried with (NSString *) object and it works fine... Thx.

2

There are 2 best solutions below

0
CodeSmile On
[myArray removeLastObject:cont];

You're trying to delete an int from the array. You wanted to use removeLastObject (no params) or removeObjectAtIndex:

Your problem may be that you're not calling removeChild:particle

6
Guru On

You must remove it from its parent not only from array.

 [part removeFromParentAndCleanup:YES];

//to remove object from array

for (int i = 0; i < [myArray count]; i++) {
        [myArray removeObjectAtIndex:i];
}

//remove only last object

        [myArray removeObjectAtIndex:([myArray count]-1)];