Does inserting an NSOperation to a NSOperationQueue increments the retain count of the NSOperation? If YES when will it get decremented?
-
1http://whentouseretaincount.com – Aug 22 '12 at 10:25
3 Answers
Please, read documentation.
- (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.

- 7,840
- 5
- 30
- 36
-
okay, I almost got it. But still a few clarifications. When do I say that an NSoperation has finished executing? Is it when the main method finishes execution? In my case from the NSoperation I am asynchronously calling a web-service and I have a call back method to catch the result. Is there any guarantee that the NSoperation will not get released till we get the response in callback method? (I am weakly referencing the NSoperation object from web-service class) – Advaith Aug 22 '12 at 10:30
from documentation
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.

- 3,453
- 4
- 33
- 58
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.

- 3,225
- 1
- 18
- 37