简体   繁体   English

保留NSOperation的计数行为

[英]Retain count behavior for NSOperation

Does inserting an NSOperation to a NSOperationQueue increments the retain count of the NSOperation? 将NSOperation插入NSOperationQueue会增加NSOperation的保留计数吗? If YES when will it get decremented? 如果是,它将何时递减?

Please, read documentation. 请阅读文档。

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html

  • (void)addOperation:(NSOperation *) operation (void)addOperation:(NSOperation *) 操作

Parameters 参数

operation 手术

The operation object to be added to the queue. 要添加到队列中的操作对象。 In memory-managed applications, this object is retained by the operation queue. 在内存管理的应用程序中,该对象由操作队列保留。 In garbage-collected applications, the queue strongly references the operation object. 在垃圾回收的应用程序中,队列强烈引用操作对象。

Discussion 讨论

Once added, the specified operation remains in the queue until it finishes executing. 添加后,指定的操作将保留在队列中,直到完成执行为止。

from documentation 从文档中

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html

Parameters. 参数。

operation. 操作。 The operation object to be added to the queue. 要添加到队列中的操作对象。 In memory-managed applications, this object is retained by the operation queue. 在内存管理的应用程序中,该对象由操作队列保留。 In garbage-collected applications, the queue strongly references the operation object. 在垃圾回收的应用程序中,队列强烈引用操作对象。

From the documentation : 文档

In memory-managed applications, this object is retained by the operation queue. 在内存管理的应用程序中,该对象由操作队列保留。 In garbage-collected applications, the queue strongly references the operation object. 在垃圾回收的应用程序中,队列强烈引用操作对象。

It wil be decremented when dequeued and processed, so you don't have to worry about it. 出队和处理时,它会减少,因此您不必担心。 Just add it to the queue and make sure you have balanced all your retain and release , and it will not leak memory. 只要将其添加到队列中,并确保已平衡所有的retainrelease ,它就不会泄漏内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM