Reputation: 3300
I'm developing an iPhone game using cocos2d.
As the player moves around and scores points by doing things, I cause little CCLabelBMFont instances to appear and then fade out (CCFadeOut). These CCLabelBMFont instances are sprites that are added to the layer.
Am I "leaking" memory or anything by not removing the faded-out sprites from the layer after they have completed the CCFadeOut action, or are they then gone, or don't need to be considered "valid"?
Upvotes: 1
Views: 1341
Reputation: 4215
After CCFadeOut has finished, the layer will keep hold of the now transparent label. You'll have to remove it from the layer manually afterwards, unless you are planning to fade it back in later, in which case you could keep it around.
It is inefficient memory usage, not a memory leak.
You aren't causing a memory leak because when the layer is deallocated it will deallocate its child nodes, including the labels, assuming you are not instantiating the labels in a way that doesn't trigger a retain.
Update: how to remove the labels after they fade out
Replace your CCFadeOut with a CCSequence that looks like this:
[yourLabel runAction:[CCSequence actions:[CCFadeOut actionWithDuration:DURATION], [CCCallFuncN actionWithTarget:self selector:@selector(removeLabel:)], nil]];
Now implement your new handler removeLabel: and make it remove the label. It takes the label as its argument.
Upvotes: 1
Reputation: 13713
CCFadeOut
does NOT remove nor releases your sprites and you should do it once their purpose is over.
Infact no action does release/remove other objects. They are only manipulating them.
Upvotes: 0