I'm using the other part, and I'm confused about the implementation of the before ccTouchesEnded: withEvent: you increase Keep the number of _nextProjectile on this line: Then at some point you have to reduce the calculation to keep the memory leak to stop. In other words: You are responsible for continuing it. This is where this line is coming: Why is it safe to issue it at that time? The code snippets in your question are actions in the sequence of both verbs. Performing an action on an object increases the number of keep on that object. This means that the action takes up the object itself and another reference to _nextProjectile is that the order of verbs is executed before the action is actually executed, so the action object is already made to _nextProjectile < / Strong> therefore it is actually safe to release it in any one verb. They were waiting for issuing _nextProjectile until these lines were passed: A release before these lines probably (I have not seen any other code from ccTouchesEnded: withEvent: ) resulted in an EXC_BAD_ACCESS runtime error. Here's some more information about maintaining: ccTouchesEnded method This is where 'shooting' is applied: player (a cannon) changes in the touched direction, and the projectile shot happens. The part which is ambiguous to me is:
_nextProjectile is being released, while it may still be in use (below the code -
_nextProjectile runAction ). Can you please tell why is it safe to release the object at this point?
- (zero) CCTE attracted: (NSSET *) touches the event: (UEVENT *) Event {[_player runAction: [CCSequence Actions: [CCRotateTo actionWithDuration: rotateDuration angle: cocosAngle], [ CCCallBlock ActionWishblock: ^ {// OK to add now - Rotation is finished! [Self combine: _nextProjectile]; [_projectiles addObject: _nextProjectile]; Release [_nextProjectile release]; _nextProjectile = Zero; }], Zero]]; // Proseclose at the actual endpoint [_nextProjectile runAction: [CCSequence actions: [CCMoveTo proceedings: realMoveDuration status: realDest], [CCCallBlockN operationWishblock: ^ (CCNode * node) {[_projectiles removal object: node]; [Node removal head and chinup: yes]; }], Zero]]; }
_nextProjectile = [[CCSprite spriteWithFile: @ "projectile2.png"];];
[_ nextProjectile release];
[_ player runAction: [CCSequence actions: ...]];
[self addChild: _nextProjectile]; [_projectiles addObject: _nextProjectile];
No comments:
Post a Comment