ios - 队列中的所有操作完成后立即释放 NSOperationQueue

标签 ios objective-c nsoperation nsoperationqueue

我想在所有正在进行的操作都执行完毕后释放 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/

相关文章:

ios - NSIncationOperation init 从类方法调用实例方法返回 nil

ios - 使用 NSPredicate 用另一个 NSArray 过滤一个 NSArray

ios - 带有普通列表的 UITableView,但使部分标题像分组列表

ios - 自定义 UIPicker - 将图像、文本和子文本放在一行中?

ios - MailCore2 - 在不下载图像或附件的情况下获取邮件内容?

ios - 在 Objective C 中设置并发执行 for 循环的最佳方法是什么?

ios - IPV6 崩溃 iOS,无法弄清楚发生了什么

ios - 最后一个单元格在底部被我的 UITabBar 切断

iphone - iOS:将 6x6 400x300px 图像添加到一张合成图像

ios - 找不到实例方法 '-addOperation:waitUntilFinished:'(返回类型默认为 'id')