MLeaksFinder
直接CocoaPods导入MLeaksFinder。
pod 'MLeaksFinder'
Pods 目录成功导入 FBRetainCycleDetector 和MLeaksFinder 之后无需修改任何程序代码 在模拟器 或真机上操作程序即可,
--代码如下
//ViewController.m
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
SecondViewController *secondVC = [[SecondViewController alloc]init];
[self.navigationController pushViewController:secondVC animated:YES];
}
//SecondViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.view.backgroundColor = [UIColor redColor];
UIBarButtonItem *leftBtn =[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(mySiteBack)];
self.navigationItem.leftBarButtonItem = leftBtn;
self.selected = ^(NSString *second){
_second =@"2";
};
}
#pragma mark--返回按钮--
- (void)mySiteBack{
[self.navigationController popViewControllerAnimated:YES] ;
}
//点击返回
MLeaksFinder 提示没有走dealloc的页面存在可能内存泄漏
IMG_0892.PNG
点击 Retain Cycle 由FBRetainCycleDetector 检测出引起循环引用的属性或对象
IMG_0893.PNG
__weak修饰解决循环引用
__weak typeof(self)Myself = self;
self.selected = ^(NSString *second){
Myself.second =@"2";
};
__block修饰并不能避免循环引用
__block typeof(self)Myself = self;
self.selected = ^(NSString *second){
Myself.second =@"2";
};
结果如下
IMG_0895.PNG IMG_0896.PNG
SecondViewController 并没有走dealloc方法
"http://www.jianshu.com/p/d73772dc36a8"__block与__weak的真正区别
网友评论