了解仪器进行内存泄漏检查 - iPhone [英] Understanding the Instrument for memory leak checking - iPhone

查看:124
本文介绍了了解仪器进行内存泄漏检查 - iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以上给出的图片是我的应用程序泄漏了。



在这里,我想了解一下,在扩展细节中 - 你可以看到不同的颜色,如浅绿色,浅粉色,浅棕色,浅紫色。 / p>

每种颜色表示什么?



现在另一个混乱是如何找到创建一个代码的代码内存泄漏?



高达内存泄漏的限制 - 实际的iPhone可以继续使用。
(假设10个字节没问题,20个字节没问题,200个字节有问题)




  • 每种颜色表示什么?

  • 哪种颜色表示我们的代码/我们可以从哪个细节获取我们分配对象的代码&忘记dealloc了吗?



(例如 - 详细点击UIKit第二个单元格 - 我们无法获取代码)




  • 为什么我们必须解决所有泄漏? - 即使是一次泄密也可以阻塞iPhone?

  • 为什么iPhone允许泄漏留在内存中? /为什么在应用程序终止后没有自动完成垃圾收集?

  • 如果我尝试释放应根据仪器解除分配的对象,我的应用程序会异常终止。如果我没有dealloc,我的应用程序运行完美,怎么样?

  • 为什么建议你在视图中等待10秒或更长时间,如果有泄漏,泄漏将可以通过仪器检测吗?


解决方案

忽略颜色,在那个[DashBoard viewDidLoad]是泄漏的来源,它是如何初始化URLConnection的(在连接完成时你可能没有释放它?)



现在回答其他问题你有:




  • 为什么我们必须解决所有泄漏? -
    即使是一次泄漏,也可以哄骗iPhone



是的。部分原因不仅在于你只是内存耗尽,而且由于整个手机只有很多内存可供使用,因此看门狗应用程序会持续监控你的应用程序并在看到内存使用时提前关闭它只有不断增长......




  • 为什么iPhone允许泄漏在内存中保留
    ? /为什么垃圾收集
    不会在
    终止申请后自动完成?



所有应用程序内存都是当应用程序退出时释放。




  • 如果我尝试释放根据
    工具取消分配
    的对象,我的应用程序
    异常终止。如果我没有
    dealloc,我的应用程序完美运行
    ,怎么样?



这里我不能帮助,你真的需要阅读更多关于保留/释放内存周期...如果你释放一个保留计数为0的对象,应用程序崩溃,因为对象已经消失。




  • 为什么建议您等待
    a查看最多10秒或更长时间,如果
    有泄漏,泄漏将是
    检测到通过仪器?



因为乐器每隔一段时间就采样一次,所以乐器可能需要一点点才能阅读行动后的记忆。


Above given images is of my application leaks.

Here I want to understand that, in Extended Detail - you can see different colors like light green, light pink, light brown, light purple.

What does each color indicates?

Now the other confusion is "How to locate the code which is creating a memory leak?"

Upto what limit of memory leak - the actual iPhone can go on with. (suppose 10 bytes no problem, 20 bytes no problem & 200 bytes a problem)

  • What does each color indicates?
  • Which color indicates our code / From which detail we can get to the code where we have allocated the object & forgot to dealloc it?

(For example - On clicking of UIKit second cell in detail - we cant get to the code)

  • Why we must resolve all the leaks? - even a single leak can chock up iPhone ?
  • Why iPhone allows leaks to be remain in memory? / why garbage collection isn't done automatically after termination of application?
  • If I try to dealloc objects which should be deallocated according to instruments, My application terminates abnormally. If I don't dealloc, My application runs perfectly, How?
  • Why it is suggested that you wait in a view up to 10 or more seconds, if there is a leak, leak will be detected by Instruments?

解决方案

Ignore the colors, in that one the [DashBoard viewDidLoad] is the source of the leak, something in how it's initializing a URLConnection (possibly you did not free that when the connection was finished?)

Now to answer the other questions you had:

  • Why we must resolve all the leaks? - even a single leak can chock up iPhone ?

Yes. Part of the reason is not only that you will simply run out of memory, but since there is only so much memory to go around for the whole phone a watchdog application is constantly monitoring your app and will shut it down early if it sees memory use only ever growing...

  • Why iPhone allows leaks to be remain in memory? / why garbage collection isn't done automatically after termination of application?

All your application memory is freed when the app quits.

  • If I try to dealloc objects which should be deallocated according to instruments, My application terminates abnormally. If I don't dealloc, My application runs perfectly, How?

Here I can't help, you really need to read more on the retain/release memory cycle... if you release an object that has a retain count of 0, the app crashes because the object is gone.

  • Why it is suggested that you wait in a view up to 10 or more seconds, if there is a leak, leak will be detected by Instruments?

Because instruments works by sampling memory every so often, so it might take a little bit for instruments to get around to reading the memory after an action.

这篇关于了解仪器进行内存泄漏检查 - iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆