Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSOperation dealloc not called when cancel operation

I am using NSOperation in my application. I am cancelling the previously executing operation when create another operation. But the previously created operation's dealloc method not calling when cancelling that operation.

Pls suggest me. Thanks.

like image 446
Bharathi Avatar asked Apr 28 '26 16:04

Bharathi


1 Answers

I think what you need is that isFinished returns YES and isExecuting returns NO after cancelled. Otherwise the operation object will never be released.

Document says.

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.

like image 175
Robasan Avatar answered May 01 '26 07:05

Robasan