我想在所有正在进行的操作都执行完毕后释放 NSOperationQueue。
到目前为止,我已经在下面编写了代码,但据我所知,waitUntilAllOperationsAreFinished
是异步调用,无法阻止我的 operationQueue 变为 nil。
- (void)deallocOperationQueue
{
[operationQueue waitUntilAllOperationsAreFinished];
operationQueue = nil;
}
最佳答案
引用 Avi
You don't need to wait for all operations to finish. Just set operationQueue to nil when you're done with it. If the queue still has operations, nothing happens to them; they will still complete.
- (void)deallocOperationQueue
{
operationQueue = nil;
}
我已经测试了代码并确认所述行为确实发生了。
关于ios - 队列中的所有操作完成后立即释放 NSOperationQueue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39015637/