異常描述:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
問題描述:
將UIWebView 轉成WKWebview后,在UMeng的錯誤里偶爾會出現幾次報錯,排查后,定位到WKWebview相關;
但問題只會出現在iOS10.0以下的系統。
在模擬器上使用8.1的系統調試確實會有這種異常,
使用malloc_error_break定位,也只能定位到內存釋放時出棧異常,沒辦法繼續調試。
原因:
通過排除法,發現只要不監聽wkwebview.scrollview的delegate,就不會異常;
想起scrollview是strong引用:
@property (nonatomic, readonly, strong) UIScrollView *scrollView;
解決方法:
將delegate設置為nil:
- (void) dealloc
{
if(_mWebViewReport)
{
_mWebViewReport.scrollView.delegate=nil;
}
}