1.打开工具
Xcode ->product->profile进入instruments工具,然后选择leaks。
2.检测
连接真机,在instruments运行,选择leaks
使用instruments leaks检测内存泄露

运行起来是这样的
使用instruments leaks检测内存泄露
这种绿色的对勾代表正常
使用instruments leaks检测内存泄露
这种红色的叉号代表有泄露
使用instruments leaks检测内存泄露
然后下方左侧可以看到发生泄露的方法,右侧可以看到调用路径。
使用instruments leaks检测内存泄露
双击方法,可以定位到具体的代码(竟然真的有泄露)
使用instruments leaks检测内存泄露

代码修改为需要重新启动,上面的截图其实已经修复完成了,只是没有重启,所以还会泄露。
最后就修复吧。
使用instruments leaks检测内存泄露

相关文章: