Re: Weird crash on iOS
Re: Weird crash on iOS
- Subject: Re: Weird crash on iOS
- From: Jens Alfke <email@hidden>
- Date: Wed, 19 Sep 2012 10:44:04 -0700
On Sep 19, 2012, at 12:36 AM, Glenn L. Austin < email@hidden> wrote: Sure. I often see people use performSelector:withObject:afterDelay: as a way to implement a "state machine" where they move from method to method using performSelector:withObject:afterDelay: as a way to "not block" the main thread. Now, imagine that the user leaves that view to go back to the main view and in order to do this you popped the navigator stack (or otherwise modified it), that view is gone when the selector is performed, and BOOM!
This is inherent to any sort of asynchronous coding. When your async completion code runs, you might not be in the appropriate state for running it. So you either have to cancel the async event, or have the handler check whether it’s still appropriate to run.
Refcounting (the original topic here) shouldn’t be an issue because the perform-after-delay implementation retains the receiver until the delayed message is performed.
A far better way is to either use a pre-defined queue of operations, or now use GCD. Whatever you do should be easily cancelable. Delayed performs are cancelable. You call [NSObject cancelPreviousPerformRequestsWithTarget: selector: object].
Sure, you can do delayed actions with GCD too. It doesn’t seem any different to me, just the syntax is changed.
—Jens
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden