I'm using a NSOperation
to handle background processing in an iOS app, and I'm trying to understand the target/action pattern. In the delegate pattern, the delegate is held as a weak reference, and the delegate object is responsible for setting the other object's delegate field to nil before it dealloc
s. In the target/action pattern, as I understand it, the target is held as a weak reference, for similar reasons. However, it doesn't seem as easy to "nil
out" the target field when the target object dealloc
s, and with NSOperation
s there is a chance the operation could still be sitting on a queue when its target is deallocated.
How should memory management be handled in this case (of a NSOperation
performing background processing, then using target/action to return a value to the creator of the NSOperation
)?