tags:

views:

412

answers:

1

I ran in to a "EXC_BAD_ACCESS" when deallocating an object that has few performSelector:withObject:afterDelay where the selector methods is calling another object and i am releasing the object ...

//some where in my class i am calling

[self performSelector:@selector(callObject1Function) withObject:nil afterDelay:2.0];


- (void)callObject1Function{
   [object1 function1]  // Here i am getting "EXC_BAD_ACCESS"
}

- (void)dealloc {
 [object1 release];
 [super dealloc];
}

I just don't understand i thought when you dealloc it the object, everything associated with the object should be removed or canceled, even the performSelector with delay !! Can some please explain, Thanks.....

+3  A: 

Use NSObject's -cancelPreviousPerformRequestsWithTarget:selector:object: to cancel any pending performs.

Ben Gottlieb
Also just NSObject's +cancelPreviousPerformRequestsWithTarget: if you want to eliminate all selector and object perform requests to that target without specifying selectors and objects
Bogatyr