try to write this code without weak reference:
[self.operationQueue addOperationWithBlock:^{
NSNumber* result = findLargestMersennePrime();
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
self.textLabel.text = [result stringValue];
}];
}];
to make this code work - compiler retains reference to self
in operationQueue
to avoid situation when self
is deleted from memory and self.textLabel.text = ..
is executed, so it tries to guarantee that object will be alive.
This is where cycle is actually created:
- self retains operationQueue (this means that operationQueue cannot be deleted while self is alive)
- operationQueue retains self (this means that self cannot be deleted while operationQueue is alive)
to avoid this - you're creating week reference, so you're eliminating 2nd retention
PS. "block" is part of operationQueue, so we can assume just 2 items in this scheme.