Even with weakSelf block still has the retain cycles problem (v1.0.3)
qiulang opened this issue · 4 comments
Even with weakSelf block still has the retain cycles problem (v1.0.3)!
__weak __typeof(self)weakSelf = self;
[self.KVOController observe:someobject
keyPath:someProperty
options:NSKeyValueObservingOptionNew
block:^(id observer, id object, NSDictionary *change) {
[weakSelf someMethod];
}
Then self never dealloc. It is easy to verify that.
If I calls [self.KVOController unobserve:someobject]; inside the block self will dealloc then. But I think it defeats the purpose of using it!
Sorry my mistake. I did not replace all the self to weakSelf (an object variable). But xcode didn't warn me against that.
I actually used another kvo block wrapper before choosing KVOController, in that case xcode can give all warnings. I don't know why xcode didn't do that for KVOController
You can turn on the -Wimplicit-retain-self
warning to get a warning if you reference self
accidentally in a block. Otherwise, this is expected behavior with Objective-C, unfortunately.
I already turned it on but xcode(7.1) failed to give the warning and that was the reason I opened the ticket in the first place.
I can't figure out why! For other retain self cases xcode was able to give warnings. It just failed on KVOController.
Hi I create another FBKVOController property (instead of using your KVOController property) and even with -Wimplicit-retain-self turning on, xcode still failed to give self retain warning. Do you know why ?