MLeaksFinder
直接CocoaPods導(dǎo)入MLeaksFinder。
pod 'MLeaksFinder'
Pods 目錄成功導(dǎo)入 FBRetainCycleDetector 和MLeaksFinder 之后無需修改任何程序代碼 在模擬器 或真機(jī)上操作程序即可,
--代碼如下
//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] ;
}
//點(diǎn)擊返回
MLeaksFinder 提示沒有走dealloc的頁面存在可能內(nèi)存泄漏
IMG_0892.PNG
點(diǎn)擊 Retain Cycle 由FBRetainCycleDetector 檢測(cè)出引起循環(huán)引用的屬性或?qū)ο?/p>
IMG_0893.PNG
__weak修飾解決循環(huán)引用
__weak typeof(self)Myself = self;
self.selected = ^(NSString *second){
Myself.second =@"2";
};
__block修飾并不能避免循環(huán)引用
__block typeof(self)Myself = self;
self.selected = ^(NSString *second){
Myself.second =@"2";
};
結(jié)果如下
IMG_0895.PNG
IMG_0896.PNG
SecondViewController 并沒有走dealloc方法
"http://www.lxweimin.com/p/d73772dc36a8"__block與__weak的真正區(qū)別