xcode 您如何找出在 Instruments 中保留对象的原因?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12113652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:19:36  来源:igfitidea点击:

How do you find out what is retaining an object in Instruments?

objective-ciosxcodememory-managementinstruments

提问by James

I've recently converted my iOS project over to ARC. One of the view controllers is not calling its dealloc method and is not being dealloc'ed according to Instruments.

我最近将我的 iOS 项目转换为 ARC。其中一个视图控制器没有调用它的 dealloc 方法,也没有根据 Instruments 被解除分配。

I've double checked all of my properties and set the appropriate ones to weak. I've also made sure that anything that has the view controller as a delegate has it unset on viewWillDisappear but the view still sticks around in memory.

我已经仔细检查了我的所有属性并将适当的属性设置为弱。我还确保任何将视图控制器作为委托的东西都在 viewWillDisappear 上未设置,但视图仍然保留在内存中。

I'm a newbie at Instruments: how can I tell what is retaining this view?

我是 Instruments 的新手:我怎么知道是什么保留了这种观点?

回答by justin

Well if you are really stuck and the program is complex (or abstracted, in the case of ARC), you can bring out the cannons:

好吧,如果你真的被卡住了,而且程序很复杂(或抽象,在 ARC 的情况下),你可以拿出大炮:

  • Open your Xcode project
  • Choose the executable (if needed)
  • Press cmd+i(Profile)
  • Choose the 'Leaks' Instrument in Le Wizard (if needed)
  • Press Return to begin profiling
  • Exercise your app
  • Press 'Stop' in Instruments
  • Verify the 'Allocations' instrument is selected
  • Click and Hold the Popup Button named 'Statistics'
  • Select the Objects List item
  • Locate the allocation you are interested in, among the records in the Objects List
  • Select that allocation/object
  • Click the 'detail arrow' to the right of the address in the table view cell of that allocation
  • Now you see all events related to the allocation (allocation, free, reference count operations)
  • Press cmd+shift+efor Extended Detail
  • Go through the events in this list, and locate the imbalance you seek.
  • 打开你的 Xcode 项目
  • 选择可执行文件(如果需要)
  • cmd+i(简介)
  • 在 Le Wizard 中选择“泄漏”仪器(如果需要)
  • 按回车键开始分析
  • 锻炼你的应用
  • 在仪器中按“停止”
  • 验证已选择“分配”工具
  • 单击并按住名为“统计”的弹出按钮
  • 选择对象列表项
  • 在 Objects List 的记录中找到您感兴趣的分配
  • 选择该分配/对象
  • 单击该分配的表视图单元格中地址右侧的“详细箭头”
  • 现在您可以看到与分配相关的所有事件(分配、空闲、引用计数操作)
  • cmd+shift+e详细信息
  • 浏览此列表中的事件,并找到您寻求的不平衡。