While writing an app, I encountered some odd behavior that I wasn’t expecting and distilled it down to the following:
I made an app whose main function is as follows. While observing it in Activity Monitor, it uses one thread.
int main(int argc, const char * argv[])
{
@autoreleasepool
{
while (YES)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
}
}
return 0;
}
If I change [NSDate distantFuture] to [NSDate dateWithTimeIntervalSinceNow:1.0], the app uses ~3 threads. After inspecting this a bit it appears that a dispatch_queue has been implicitly created on my behalf which in turn makes a thread pool.
Just curious: why does this happen? What about [NSDate dateWithTimeIntervalSinceNow:1.0] causes the run loop to create a dispatch_queue?
Most likely, an implementation detail and nothing to worry about….
One possibly implementation of
distantFutureis “do it forever” and, therefore, no need for a timer like the one w/a specific date. Given that “timer” might actually bedispatch_after(), that might explain the queue.Or not. Interesting question, but likely quite thoroughly irrelevant to your app.