Game Development Reference
The Spider class is registered with CCTouchDispatcher to receive input as a
touch delegate, but this delegate association must also be removed on cleanup .
Otherwise, the scheduler or touch dispatcher would still keep a reference to the
Spider class even though it was released from memory, and that would likely cause a
crash shortly thereafter. And it must be in the cleanup method, not dealloc , for
the simple reason that the touch dispatcher holds (retains) a reference to your class. If
you don't instruct the touch dispatcher to remove your class, it will never be dealloc-
Listing 5-14. The Changed Spider Class
if ((self = [super init]))
// Manually add this class as receiver of targeted touch events.
[[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self
// Must manually remove this class as touch input receiver!
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
// Extract common logic into a separate method accepting parameters.
-(void) moveAway:(float)duration position:(CGPoint)moveTo