I'm trying to track down a memory leak and wanted to know how this works. In the BaseHelper class, there is a property for a sessionManager:
BaseHelper
@property(nonatomic, strong) SessionManager *sessionManager;
- (void)setup {
__weak typeof(self) weakSelf = self;
[self.sessionManager reachabilityChanged:^(BOOL isReachable) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf reachabilityChanged:isReachable];
});
}]
}
So far, this part looks ok to me since it's using weakSelf to call reachabilityChanged.
- (void) reachabilityChanged:(BOOL)isReachabile {
__block typeof(self) __weak weakSelf = self;
[self fetchSettingsWithCompletion:^(BOOL success, NSError * _Nullable error) {
if (success){
[weakSelf processSettings];
} else if (!success &&
!error){
[weakSelf errorHandling];
}
}];
}
Again, this part looks ok to me since it's using weakSelf.
- (void) processSettings {
// New, saved, or default publish settings?
[self setupLogger];
[self setupOtherProperties];
}
Here if you don't use weakSelf and in other methods like setupLogger
or setupOtherProperties
if you don't reference weakSelf again, do you run the risk of capturing properties on the main object and having a retain cycle?