简体   繁体   中英

Retain count behavior for NSOperation

Does inserting an NSOperation to a NSOperationQueue increments the retain count of the 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

  • (void)addOperation:(NSOperation *) operation

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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