- 使用MLeaksFinder工具
在viewWillDisappear方法中
[super viewWillDisappear:animated];
FBRetainCycleDetector *detector = [FBRetainCycleDetector new];
[detector addCandidate:self];
NSSet *retainCycles = [detector findRetainCycles];
NSLog(@"%@", retainCycles);
打印結(jié)果(
"-> _analystView -> QLAnalystView ",
"-> _analystViewBtnClick -> __NSMallocBlock__ ",
"-> QLDiscoverDetailViewController "
),這代表有循環(huán)引用念脯。
打印結(jié)果(
"-> _analystView -> QLAnalystView ",
"-> _analystViewBtnClick -> __NSMallocBlock__ ",
"-> QLDiscoverDetailViewController "
),這代表有循環(huán)引用螺捐。
我的代碼展示
@property (nonatomic ,copy) void(^analystViewBtnClick)(BOOL isShowOnlyAnalyst);
- (void)analystBtnClick{
if (self.analystViewBtnClick) {
self.analystViewBtnClick(_isShowOnlyAnalyst);
}}
@interface QLAnalystView(){
BOOL _isShowOnlyAnalyst;
}
問題分析:屬性帶下劃線會(huì)暗自引用self处硬,所以會(huì)讓計(jì)數(shù)器加一塌西,導(dǎo)致不釋放掰邢。把這個(gè)屬性 定義為這樣@property (nonatomic ,assign) BOOL isShowOnlyAnalyst;就ok了
- 另外一個(gè)問題是WKWebView的問題
WKUserContentController *userCC = config.userContentController;
[userCC addScriptMessageHandler:weakSelf name:@"share"];
[userCC addScriptMessageHandler:weakSelf name:@"transmitData"];
3.內(nèi)存泄漏(靜態(tài)檢測)
1,Property of mutable type 'NSMutableDictionary' has 'copy' attribute; an immutable object will be stored instead()
2吭服,Value stored to 'dataArr' during its initialization is never read(存在一塊內(nèi)存空閑了嚷堡,所以就存在了內(nèi)存泄漏)
當(dāng)使用這個(gè)時(shí),會(huì)讓控制器無法釋放艇棕。解決方案請(qǐng)參考這個(gè)鏈接