Hi,
cocos2d v0.7.x is retaining the "targets" in the actions an also in the Timers.
This means that when you schedule an action or a "Timer" the node will be retained.
Some of the benefits are that from an action you can remove the node, and that code won't crash (because the action is retaining the node).
But it seems that retaining the "target" is a bad practice, and CocoaTouch is not retaining the target in their target-action pattern.
(see this discussion: http://code.google.com/p/cocos2d-iphone/issues/detail?id=150 )
v0.8 is not retaining the "target" when you run an action, but it is retaining the "node" when you schedule a Timer, which is more or less the same as retaining the "target" in the action.
And I would like to remove the "retain" from the Timer as well.
This means that if you are removing a node from an action, and if that node is running an action, I'm 99% confident that your code will crash.
So, I was thinking of adding a new way to remove nodes.
eg:
a)
// Safely removes self from parent. The remove won't be immediately. Instead it will be executed from an scheduled method.
-(void) removeFromParentWithCleanup:(BOOL)cleanup;
b)
// add 3 new ways to remove objects:
// as in a), these methods will schedule a method, and the nodes
// will be removed from the scheduled method.
-(void) safelyRemoveChildByTag:cleanup:;
-(void) safelyRemoveChild:cleanup:;
-(void) safelyRemoveAllChildrenWithClean:;
c)
other options ???
a) or b) or c) should be called when you try to remove a node from an scheduled action.
This means that the programmer should modify his code a little bit, and he should pay attention when he is removing the nodes.
benefits:
- No more strange bugs like #422 and #421 (and I would like to point out that these bugs were not easy to debug because of the circular retains)
- The code is simpler: easier to maintain. Less prone to bugs. Easier to debug.
My question is,
which API would you like to have ?
a) ? b) ? c) ?
thanks