2

I tried to figure out when will the NSFireDelayedPerform be triggered and what's the basic rule of this. But I could not find any documentation or source code mentioning about this. Can anybody provide a little hint?

hol
  • 8,255
  • 5
  • 33
  • 59
Pei
  • 460
  • 4
  • 21

2 Answers2

6

I encountered this too and believe this may be called whenever a selector is to be performed after a specified delay (below it's 2 seconds).

[foo performSelector:@selector(f1) withObject:nil afterDelay:2];

Below is from the stack trace on the main thread where the app was killed after a delay of 20.060 seconds. Despite the specified 2 second delay, the system took much longer (over 10s) to perform this selector. This implies that the system uses an NSTimer to process the performSelector calls with the afterDelay parameter. Unfortunately, it seems to perhaps put the call on the event queue of the main thread and then wait for the specified delay (or more):

6 Foundation 0x35bfaa6a __NSFireDelayedPerform

7 CoreFoundation 0x3add45dc CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 12

Community
  • 1
  • 1
paiego
  • 3,619
  • 34
  • 43
0

I would start here

https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16-SW1

there is no mentioning of NSFireDelayedPerform but it makes somehow sense as this is normally seen in the context of CFRunLoop.

Also maybe you want to look here:

Is there any guide for iOS runloop mechanism?

Or actually even more basic:

http://developer.apple.com/library/ios/#documentation/general/conceptual/Devpedia-CocoaApp/MainEventLoop.html

Community
  • 1
  • 1
hol
  • 8,255
  • 5
  • 33
  • 59
  • Thanks for your reply. Actually I experienced certain scenario as for the same UI interaction, this "NSFireDelayedPerform" will some times be called but not for the other. Such as for UITableView scroll or selection, if interact really crazy, this "NSFireDelayedPerform" will likely be triggered. – Pei Sep 18 '12 at 23:17