detachNewThreadSelector:toTarget:withObject:
Detaches a new thread and uses the specified selector as the thread entry point.
Parameters
-
aSelector
-
The selector for the message to send to the target. This selector must take only one argument and must not have a return value.
aTarget
-
The object that will receive the message aSelector on the new thread.
anArgument
-
The single argument passed to the target. May be
nil.
Discussion
For non garbage-collected applications, the method aSelector is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits. Garbage-collected applications do not need to create an autorelease pool.
The objects aTarget and anArgument are retained during the execution of the detached thread, then released. The detached thread is exited (using the exit class method) as soon as aTarget has completed executing the aSelectormethod.
If this thread is the first thread detached in the application, this method posts theNSWillBecomeMultiThreadedNotification with object nil to the default notification center.
本文详细介绍了Objective-C中使用detachNewThreadSelector方法创建新线程的过程。该方法通过指定的目标对象及选择器来设置线程入口,并传递必要的参数。文章还提到了垃圾回收环境下自动释放池的使用差异。

1221

被折叠的 条评论
为什么被折叠?



