- 使用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(存在一块内存空闲了,所以就存在了内存泄漏)
当使用这个时,会让控制器无法释放。解决方案请参考这个链接
网友评论