AC在应用中大量使用了block,由于Objective-C语言的内存管理是基于引用计数的,为了避免循环引用问题,在block中如果要引用self,需要使用@weakify(self)和@strongify(self)来避免强引用。
一、block的循环引用问题
- -(void)loadView
- {
- [superloadView];
- _observer=[[NSNotificationCenterdefaultCenter]addObserverForName:@"testKey"
- object:nil
- queue:nil
- usingBlock:^(NSNotification*note){
- [selfdismissModalViewControllerAnimated:YES];
- }];
- }
- -(void)dealloc
- {
- [[NSNotificationCenterremoveObserver:_observer];
- }