I usually get a warning when I call anything on self in a block retained by self:
[self.someView doSomething:^{
self.aVar = @"Hello!";
}];
I have to do:
__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello!";
}];
But if I call a method on weakSelf, and that method uses self, will that lead to a retain cycle even though I don’t get a warning? I am talking about this:
__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello!";
[weakSelf aMethod];
}];
and aMethod uses self
As long as your
weakSelfis declared outside your block, there is no retain cycle.Use of objects inside the block implicitly increments the retain count. But you’d be calling
aMethodonweakSelfrather thanself, so the retain count is not affected.