bas*_*ibe 11 concurrency cocoa objective-c autorelease
我有一个需要相当长时间的任务,应该在后台运行.根据文档,这可以使用NSOperationQueue.但是,我不想保留类的全局副本,NSOperationQueue因为我实际上只将它用于那个任务.因此,我只是将其设置为自动释放,并希望在任务完成之前不会释放它.有用.
像这样:
NSInvocationOperation *theTask = [NSInvocationOperation alloc];
theTask = [theTask initWithTarget:self
selector:@selector(doTask:)
object:nil];
NSOperationQueue *operationQueue = [[NSOperationQueue new] autorelease];
[operationQueue addOperation:theTask];
[theTask release];
Run Code Online (Sandbox Code Playgroud)
不过,我有点担心.这保证有效吗?或者可能operationQueue会在某个时候取消分配并接受theTask它?
| 归档时间: |
|
| 查看次数: |
2281 次 |
| 最近记录: |