2

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?

aryaxt
  • 76,198
  • 92
  • 293
  • 442
  • http://stackoverflow.com/questions/4688118/does-performselectorinbackground-spawn-new-thread-for-each-call – Kazuki Sakamoto Feb 28 '11 at 23:54
  • @Kazuki Sakamoto - These are different questions, IMO. The question you linked asks about the internals of -performSelectorInBackgroun:withObject: while this question asks to clarify the difference between two selectors. – Jason Coco Mar 01 '11 at 00:01
  • GCD is not available on iphone :( – aryaxt Mar 01 '11 at 00:49

1 Answers1

4

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 performSelector style 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.

Jason Coco
  • 77,985
  • 20
  • 184
  • 180