Mason
Mason

Reputation: 767

what does setting cleanup to YES do in cocos2d removeChild?

I think I might be causing a bug in my code because I'm unclear about what the cleanup: part of removeChild:cleanup: method of cocos2d ccnode class.

Thanks.

Upvotes: 3

Views: 3140

Answers (2)

YvesLeBorg
YvesLeBorg

Reputation: 9079

It stops all actions and unschedules any scheduled selectors associated with the CCNode, basically removing any references that cocos could have to the object. It also propagates the cleanup invocation to all of the object's children. If the object is an autorealease-able object and you did not retain a reference to it, the memory should be reclaimed by the objective-c runtime, for the object itself and its children. That would be true of almost all objects, but not if you added the objected as a targeted touch delegate. In that case, I would recommend to override the onExit method as this:

- (void) onExit{
    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    [super onExit];
}

this way, the object will be fully release-able when you cleanup.

Upvotes: 7

X Slash
X Slash

Reputation: 4131

cleanup basically specifies whether the running actions for that particular node should be cleaned up or not, basically, if it's set to YES, the object that's being removed will stop all running actions and unschedule all selectors.

Upvotes: 1

Related Questions