ios - 取消操作时不调用 NSOperation dealloc

标签 ios nsoperation

我在我的应用程序中使用 NSOperation。 创建另一个操作时,我正在取消先前执行的操作。但是之前创建的操作的 dealloc 方法在取消该操作时没有调用。

请建议我。 谢谢。

最佳答案

我认为您需要的是 isFinished 返回 YES 并且 isExecuting 在取消后返回 NO。否则永远不会释放操作对象。

文档说。

In addition to simply exiting when an operation is cancelled, it is also important that you move a cancelled operation to the appropriate final state. Specifically, if you manage the values for the isFinished and isExecuting properties yourself (perhaps because you are implementing a concurrent operation), you must update those variables accordingly. Specifically, you must change the value returned by isFinished to YES and the value returned by isExecuting to NO. You must make these changes even if the operation was cancelled before it started executing.

关于ios - 取消操作时不调用 NSOperation dealloc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9493590/

相关文章:

javascript - 仅在 WKWebView 网页完全加载后运行注入(inject)的 JavaScript 脚本

iphone - 为 NSOperationQueue 设置并发操作只会导致该数量的操作

iphone - 如何在不阻塞 UI 的情况下将内容加载到 TableView 中?

ios - 如何使用 Facebook 图形 API 识别 Facebook 帖子是否已被点赞?

ios - Xcode5中的 "other storyboard compiler flags"是什么

ios - UIButton 在 UITableView 中不工作(点击时崩溃)?我能得到一些关于 obj-c 的帮助吗

ios - 当 Sprite 被触摸并移出节点(按钮)边界时如何停止 Sprite 的移动

objective-c - 为什么垃圾收集不适用于线程?

objective-c - 用于核心数据操作的 NSOperation

iphone - NSAssert 在线程中的使用