引爆自动释放的NSOperationQueue是危险的吗?

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它?

Nic*_*ore 5

文档中没有任何内容可以说明NSOperationQueue发布时会发生什么.假设无法保证任务将被执行是最安全的.