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”?
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:
Now implement your new handler removeLabel: and make it remove the label. It takes the label as its argument.