Question about block, ARC, self, and reference counting.
Question about block, ARC, self, and reference counting.
- Subject: Question about block, ARC, self, and reference counting.
- From: Scott Andrew <email@hidden>
- Date: Thu, 12 Apr 2012 10:04:22 -0700
I have a question about retain cycles with ARC and blocks.
I have the following code:
__weak MyViewController* controller = self;
[UIView animateWithDuration:.25 animations:^{
controller.alpha = 0;
}
completion:^(BOOL finsihed) {
[controller showState];
}];
-(void) showState {
self.textView.text = self.stateText;
}
I have a question about what happens when I use self in showState. DId i just cause a reference counting issue where I now have an extra retain on self and it's not going to be cleaned up? The WWDC video say to use weak pointers to self in the block otherwise there could be retain cycle issues. This is an example. The utility functions are actually quite larger and called from multiple places. I'm not creating the strong refrence via a variable because these blocks won't be called if self doesn't exist.
Scott
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden