在Cocoa中ARC下,我可以得到一个对象的引用到另一个对象的列表(通过编程或使用Instruments)? [英] In Cocoa under ARC can I get a list of objects that have references to another object (either programmatically or using Instruments)?

查看:120
本文介绍了在Cocoa中ARC下,我可以得到一个对象的引用到另一个对象的列表(通过编程或使用Instruments)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试我的Cocoa应用程序,并注意到使用Instruments.app分配配置文件,模型对象图不是如预期的那样释放。基本上当我从我的NSDocument中删除一个根模型对象,我期望该对象的整个对象图被解除分配。这不会发生,这意味着有一个强大的引用我的根模型对象在应用程序中的其他地方。

I am debugging the my Cocoa application and noticed using the Instruments.app allocation profile that the model object graph is not deallocating as I expect. Basically when I remove a root model object from the my NSDocument I was expecting the whole object graph for that object to be deallocated. That doesn't happen, which means that there is a strong reference to my root model object somewhere else in the application.

可以获得一个对象的列表在Cocoa中通过编程或使用Instruments.app来引用特定对象?如果我能知道强引用的位置,这将有助于调试这个问题。

Is it possible to get a list of object which have a reference to a specific object in Cocoa either programmatically or using Instruments.app? If I could know where the strong reference is held this would help with debugging this problem.

我发现了类似的问题,如何获取NSObject的引用计数?,但这只是简单地说, ,而不是哪些对象包含引用。

I found this similar question, How to get the reference count of an NSObject?, but this simply says which how many references there are, not which objects hold the references.

推荐答案

不是这样。存储在正在运行的进程中的唯一信息是对象上的保留数(保留次数已被称为释放被调用的次数)。这与引用的数量(强指向存储器的指针的数量)不同。大多数内存位置没有在Cocoa指向他们的东西的侧边表。

Not in this way. The only information that is stored inside of a running process is the number of retains on an object (number of times "retain" has been called net the number of times "release" has been called). This is not the same as the number of references (number of "strong" pointers to the memory). Most memory locations do not have a side table of things that point to them in Cocoa.

在Instruments中,您可以打开记录引用计数计数增加或减少。请参见仪器分配轨alloc和dealloc的用户定义类的对象,以了解如何做到这一点的一个很好的解释。这不会告诉你你犯了什么错误,但它会告诉你保留在哪里发生。

In Instruments, you can turn on "record reference counts" and see everywhere the retain count is increased or decreased. See Instruments Allocations track alloc and dealloc of objects of user defined classes for a good explanation of how to do that. This won't tell you where you've made your mistake, but it will tell you where the retains are occurring.

这篇关于在Cocoa中ARC下,我可以得到一个对象的引用到另一个对象的列表(通过编程或使用Instruments)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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