转自:http://www.cnblogs.com/Sanje3000/p/6953118.html
异常描述:
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(_webView)
{
_webView.scrollView.delegate=nil;
}
}