0

I been having a bit of a discussion in regards to weakify and strongify. I understand that you need to first weakify and then strongify for a block if there is a retain cycle.

i.e self(view controller) owns a label which owns a block (strong ref) and inside the block callback the there is a reference to self . I understand that they all link to each other strongly hence the retain cycle.

However, should the below have a weakify and strongify as I don't see any retain cycle since the declaration of phoneviewcontroller is local. Been quite confused with this. Please note that view controller has an @property copy to the setfinishblock.

- (void) doSomething{    
PhoneViewController *viewController = [[PhoneViewController alloc]    initWithNibName:@"xxxxx" bundle:nil];

@weakify(self)
[viewController setFinishBlock:^(UIImage *image) {
    @strongify(self)
    [Sharedmanager dosomethign:something];
}];

}

Thanks.

user281300
  • 1,427
  • 2
  • 19
  • 31
  • I already checked those answers, they aren't the same as his variable isn't local and is being retained by the owner. Mine is a local variable which is not retained. I think there is no retain cycle here. I already did a lot of googling and reading answers before posting this. – user281300 Jan 28 '16 at 22:35
  • You are right, no need to do `weakify` and `strongify` in this case – Eric Qian Jan 28 '16 at 22:52
  • The Block doesn't even use `self`; why would a weak reference be necessary? – jscs Jan 28 '16 at 23:01
  • Yes it doesn't but in do something, there could be a reference to self if i.e. do something takes i.e a label that is retained by self. – user281300 Jan 28 '16 at 23:15

0 Answers0