简体   繁体   English

ARC循环保留检测

[英]ARC circular retain detection

I ported some old code over to Objective-C ARC (Automatic Reference Counting) and it seems to work great. 我将一些旧代码移植到Objective-C ARC(自动引用计数),它看起来效果很好。 Except a rather large, high-level object is not being deallocated when it is popped off of my navigation stack, making me believe I have a retain cycle somewhere that ARC has hidden from me (or at least made difficult to track down). 当一个相当大的高级对象从我的导航堆栈中弹出时,它不会被释放,让我相信我有一个ARC隐藏在我身边的某个保留周期(或者至少很难跟踪)。 What is the best way to weed out this potential retain cycle and/or what is a good way to determine the cause of a memory leak under ARC? 清除这个潜在保留周期的最佳方法是什么和/或什么是确定ARC下内存泄漏原因的好方法? Thanks! 谢谢!

I just transitioned an older app to use ARC. 我只是转换了一个较旧的应用程序来使用ARC。 Instruments showed no leaks, but the allocations continued to go up. 仪器没有泄漏,但分配继续增加。 I found that by looking at the live objects for something that I knew should be deleted, I was able to track down the retains without a release. 我发现通过查看我知道应该删除的内容的实时对象,我能够在没有发布的情况下追踪保留。 Here are the basic steps: 以下是基本步骤:

  1. Use the Allocations tool in Instruments 使用仪器中的分配工具
  2. Play with your app for a while (if you know what isn't being released, this goes faster) 玩你的应用程序一段时间(如果你知道什么没有发布,这会更快)
  3. Change Statistics to Objects in the Allocations jump bar 将统计信息更改为“分配”跳转栏中的对象
  4. Sort by Category and find the class name of your unreleased object 按类别排序,找到未发布对象的类名
  5. Find a living instance and click the little right arrow next to the memory address 找到一个活动实例,然后单击内存地址旁边的小右箭头
  6. Now you can see the history of retains and releases for an object 现在,您可以查看对象的保留和释放历史记录

仪器中对象历史的屏幕截图

The best way is usually to use the Leaks instrument in the Instruments app . 最好的方法通常是在仪器应用程序中使用Leaks仪器

The What's New In Instruments video from WWDC 2011 discusses using Instruments to find retain cycles under ARC, starting about 38 minutes in. 来自WWDC 2011的什么是新的仪器”视频讨论了使用仪器在ARC下找到保留周期,从大约38分钟开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM