Both detachNewThreadSelector and performSelectorInBackground are used to call a method in the background.
Is there any difference between the 2 methods? or do they both work the same way?
answer:
They're both essentially the same but slightly different paradigms. Behind the scenes they do exactly the same thing. The only real difference is that -[performSelectorInBackground:withObject:]
follows all the other performSelectorstyle methods in that they're defined on NSObject
and you actually message that defines the selector you wish to perform.
In general, you should almost never have to call either of these methods. Favor using Grand Central Dispatch or NSOperation
and NSOperationQueue
to factor out expensive operations on other threads. Both GCD and the NSOperation
classes give you memory management, thread pool management and many other things you'll miss using the older style dispatch methods.