查找使用ARC保留对象的位置 [英] Find where object is retained with ARC

查看:105
本文介绍了查找使用ARC保留对象的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个保留得比必要更多的对象(最有可能是由于该属性是strong而不是weak).大型代码库,因此很难找到位置.

I have an object that is being retained more than necessary (most likely due to a property that is strong instead of weak). Big codebase, so it's hard to find where.

在使用ARC时如何找到保留该对象的所有行?

How can I find all the lines in which this object is being retained when using ARC?

如果我不使用ARC,我想我可以简单地覆盖retain并从调用位置进行检查.我可以使用ARC做类似的事情吗?

If I weren't using ARC I guess I could simply override retain and check from where it's called. Can I do something similar with ARC?

推荐答案

要跟踪应用程序的增长,

To track growth of an application, Heapshot Analysis has proven very effective. It will capture both true leaks and accretion of memory where the allocations are not accounted for by leaks.

您可以使用分配工具查看所有保留/释放事件及其回溯.点击分配工具上的小(i)按钮,然后打开记录参考计数".启用仅跟踪活动分配"功能会减少Instruments收集的数据量,使其变得更加清晰(在这种情况下,无效分配并不是真正有用,但在其他情况下也可能有用).

You can see all of the retain/release events, and their backtrace, using the Allocations instrument. Hit the little (i) button on the Allocations instrument and turn on "Record reference counts". Turning on "Only track active allocations" reduces the amount of data collected by Instruments, making it snappier (and dead allocations aren't really useful in this context, but can be in others).

这样,您就可以进行任何分配(通过单击地址字段中的右箭头),查看所有保留/释放事件,并确切了解它们的发生位置.

With that, you can dive into any allocation (by clicking on the right-arrow in the address field), see all the retain/release events and see exactly where they occurred.

这篇关于查找使用ARC保留对象的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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