ARC圆形保留检测

发布于 2025-01-02 09:12:24 字数 164 浏览 2 评论 0原文

我将一些旧代码移植到 Objective-C ARC(自动引用计数),它似乎工作得很好。除了一个相当大的高级对象在从我的导航堆栈中弹出时没有被释放,这让我相信我在 ARC 隐藏的某个地方有一个保留周期(或者至少很难追踪)。消除这种潜在保留周期的最佳方法是什么和/或确定 ARC 下内存泄漏原因的好方法是什么?谢谢!

I ported some old code over to Objective-C ARC (Automatic Reference Counting) and it seems to work great. 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). 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? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

や三分注定 2025-01-09 09:12:24

我刚刚将一个旧应用程序转换为使用 ARC。仪器显示没有泄漏,但分配量继续增加。我发现,通过查看活动对象中是否有我知道应该删除的内容,我能够在不释放的情况下追踪保留。以下是基本步骤:

  1. 使用 Instruments 中的分配工具
  2. 玩一下您的应用程序(如果您知道哪些内容尚未发布,这会更快)
  3. 将统计信息更改为分配跳转栏中的对象
  4. 按类别排序并找到类未释放对象的名称
  5. 找到一个活动实例,然后单击内存地址旁边的小右箭头
  6. 现在您可以看到对象的保留和释放历史记录

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

I just transitioned an older app to use 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

Screenshot of object history in Instruments

私野 2025-01-09 09:12:24

最好的方法通常是使用 仪器应用程序中的 Leaks 仪器

WWDC 2011 中的What's New In Instruments视频讨论了 Instruments 的使用查找 ARC 下的保留周期,大约从 38 分钟开始。

The best way is usually to use the Leaks instrument in the Instruments app.

The What's New In Instruments video from WWDC 2011 discusses using Instruments to find retain cycles under ARC, starting about 38 minutes in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文