I know...one more question to this topic. But I really don't get it.
My code:
//MyViewController.h
@property (strong, nonatomic) UIPageViewController *pageViewController;
//MyViewController.m
- (void)setViewControllerForIndex:(NSInteger)index {
[self.pageViewController setViewControllers:_myViewControllers[index]
direction:UIPageViewControllerNavigationDirectionForward
animated:animated
completion:^(BOOL finished){
[self updatedViewControllerTo:index]; //this method is doing a lot of stuff
}];
}
Do I have a retain cycle now?
self
is being captured in the completion block and self
has a strong reference to the pageViewController
and so indirectly I have a retain cycle?
Do I have to use the __weak MyViewController *weakSelf
statement and use weakSelf
in the completion block?
Or: Even when I have a retain cycle does it matter? When the block finishes all the objects in the block will be released and so the retain cycle (or the strong reference to self) will be released, too?
The method updatedViewControllerTo:
is doing also UI changes. So the method has to be called. When I'm using weakSelf
do I have to create a strong reference of self
in the block? (Referencing to the last code block at http://masteringios.com/blog/2014/03/06/avoid-strong-reference-cycles/).