我的工作---IOS内存泄露


一.Debug navigator中的Memory


1、从svn导入ios的app源码到xcode

2、选择:Product---Run,运行app

3、选择标红的部分:Debug navigator


4、可以显示cpu、内存的使用情况




5、如果内存使用一直变大,可能有些内存没有释放,会存在内存泄露(循环引用导致的 Abandoned memory


备注:

Leaks

先看看 Leaks,从苹果的开发者文档里可以看到,一个 app 的内存分三类:

  • Leaked memory: Memory unreferenced by your application that cannot be used again or freed (also detectable by using the Leaks instrument).

  • Abandoned memory: Memory still referenced by your application that has no useful purpose.

  • Cached memory: Memory still referenced by your application that might be used again for better performance.

其中 Leaked memory 和 Abandoned memory 都属于应该释放而没释放的内存,都是内存泄露,而 Leaks 工具只负责检测 Leaked memory,而不管 Abandoned memory。在 MRC 时代 Leaked memory 很常见,因为很容易忘了调用 release,但在 ARC 时代更常见的内存泄露是循环引用导致的 Abandoned memory,Leaks 工具查不出这类内存泄露,应用有限。



备注:

 怎么进行app内存测试

(1) 用Leaks检测内存泄露
(2) 反复进入退出一个功能页面,在Debug navigator中看内存是不是持续上升。内存持续上升说明内存漏了。




二.Instruments

启动Instruments的方法是,Product->Profile,经过漫长的编译时间后,出现Instruments界面,下图


Instruments中,可以分析内存的工具有Activity Monitor,Allocations,Leaks。

(1)Leaks

Leaks检测内存泄露的工具,很有用。Leaks运行中,看到下面这个红叉叉就表示有内存泄露了



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值