ARC圆形保留检测
我将一些旧代码移植到 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚将一个旧应用程序转换为使用 ARC。仪器显示没有泄漏,但分配量继续增加。我发现,通过查看活动对象中是否有我知道应该删除的内容,我能够在不释放的情况下追踪保留。以下是基本步骤:
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:
最好的方法通常是使用 仪器应用程序中的 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.
X-code 8 引入了内存图调试工具:
查看此处以获取完整参考:
https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/special_debugging_workflows.html#//apple_ref/doc/uid/TP40015022-CH9-DontLinkElementID_1
X-code 8 introduced the Memory graph debugging tool:
have a look here for full reference:
https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/special_debugging_workflows.html#//apple_ref/doc/uid/TP40015022-CH9-DontLinkElementID_1