开发者

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

开发者 https://www.devze.com 2022-12-17 09:48 出处:网络
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.

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号