I try to track my sprites in an array, add and remove them from layers, and then permanently clear them from the array.
I am using the following code:
Sprite * Trees[50];
Layer * Forest;
Forest = [Layer node];
Forest.isTouchEnabled = YES;
[self addChild:Forest z:30];
Trees[0] = [[Sprite spriteWithFile:@"mytree.png"] retain];
[Trees[0] setPosition:cpv(240,160)];
[Forest addChild:Trees[0] z:5];
And then when I want to destroy the tree, I use:
[Forest removeChild:Trees[0] cleanup:YES];
[Trees[0] release];
My problem is that when I look in the "Tools", I never come back, this memory never falls. I thought that by freeing the sprite, it would free up memory. Am I doing this completely wrong?
source
share