I looked through some documents explaining how to manage NSOperation inside an NSOperationQueue. My goal is to always not perform the operation at all if the user clicked the cancel button on the progress bar or left the application. And thus, cancel the operation to prevent unnecessary consumption of CPU time.
So, whenever I need to cancel the operation, I have to start the cancel method to prevent further execution. Then I will need to use the state of the operation object. Dispatched at regular intervals to check if the operation has been canceled. Here are my questions regarding this:
(1) When canceling a request, if NSOperation is removed from NSOperationQueue, then how do we still refer to this NSOperation and its isCancelled property?
In accordance with the reference to the class Developer Developer, Apple's: . The NSOperationQueue class controls the execution of a set of NSOperation objects. Once added to a queue, an operation remains in that queue until it is explicitly canceled or completed by completing its task. "
(2) If I use ARC, should I take care to cancel the request? I gave an example. I have 2 controllers of type A and B. In B, I do 8 to 10 NSURLRequest using NSOperation, and put all the queries in NSOperationQueue. Here, the NSOperationQueue object is a property of the view controller B. Thus, if the user presses the back button to return to view A, in ARC the NSOperationQueue object should be automatically deleted (as I pop to view A). Will all operations be canceled by the ARC mechanism, or should I still have some kind of mechanism to avoid useless execution?
Correct me if I am wrong. The answer and suggestion on this question will undoubtedly help me develop applications with better performance.
Appreciate your advice. Thanks in advance.