Instrument 检测内存泄漏

打开 Instruments

  • 方法一:Xcode > Open Developer Tool > Instruments
  • 方法二:Product > Profile
  • 方法三:如下图 Open Instruments

选择 Leaks

  • 选择 Leaks 选项进入内存检测界面

检测

  • 点击红色按钮开始检测

  • 点击 leaks 行,同时操作 App,出现红色叉符号时,就监测到了内存泄露,此时可以暂停检测。

定位问题

  • 选择 Call Tree

  • 选中Invert Call Tree 和Hide System Libraries

  • 双击条目即可跳转到内存泄漏的代码处