- 使用MLeaksFinder工具
在viewWillDisappear方法中
[super viewWillDisappear:animated];
FBRetainCycleDetector *detector = [FBRetainCycleDetector new];
[detector addCandidate:self];
NSSet *retainCycles = [detector findRetainCycles];
NSLog(@"%@", retainCycles);
打印結果(
"-> _analystView -> QLAnalystView ",
"-> _analystViewBtnClick -> __NSMallocBlock__ ",
"-> QLDiscoverDetailViewController "
),這代表有循環引用。
打印結果(
"-> _analystView -> QLAnalystView ",
"-> _analystViewBtnClick -> __NSMallocBlock__ ",
"-> QLDiscoverDetailViewController "
),這代表有循環引用。
我的代碼展示
@property (nonatomic ,copy) void(^analystViewBtnClick)(BOOL isShowOnlyAnalyst);
- (void)analystBtnClick{
if (self.analystViewBtnClick) {
self.analystViewBtnClick(_isShowOnlyAnalyst);
}}
@interface QLAnalystView(){
BOOL _isShowOnlyAnalyst;
}
問題分析:屬性帶下劃線會暗自引用self,所以會讓計數器加一,導致不釋放。把這個屬性 定義為這樣@property (nonatomic ,assign) BOOL isShowOnlyAnalyst;就ok了
- 另外一個問題是WKWebView的問題
WKUserContentController *userCC = config.userContentController;
[userCC addScriptMessageHandler:weakSelf name:@"share"];
[userCC addScriptMessageHandler:weakSelf name:@"transmitData"];
3.內存泄漏(靜態檢測)
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(存在一塊內存空閑了,所以就存在了內存泄漏)
當使用這個時,會讓控制器無法釋放。解決方案請參考這個鏈接