How can I remove all performSelector:withObject:afterDelay:?

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.

Somewhere in my class I am calling:

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

and in my class I have:

- (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!

Answers


Use NSObject's:

-cancelPreviousPerformRequestsWithTarget:selector:object: 

to cancel any pending perform selectors.


I have used following code in my all apps and it's working.

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(MethodName) object:nil];

Thanks, Hemang.


Need Your Help

"Retrieving the COM class factory for component.... error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

asp.net excel iis

I just created a simple application and hosted in IIS6.0. In code I'm just instantiating excel objects.

Image aspect ratio using Reportlab in Python

python image pdf reportlab

I want to insert an image inside a frame. I found two ways to do this: