如何获取NSObject的引用计数? [英] How to get the reference count of an NSObject?
问题描述
有没有办法获取NSObject(即NSString)的当前引用计数?
Is there a way to fetch the current reference count for an NSObject (i.e. NSString)?
推荐答案
As @Ben S说,它是 retainCount
方法。但是,您提出的问题是错误的,因为:
As @Ben S said, it's the retainCount
method. However, you're asking the wrong question, because:
重要 :通常没有理由明确要求对象的保留计数是什么(参见 retainCount )。结果通常是误导,因为你可能不知道什么框架对象保留了你感兴趣的对象。在调试内存管理问题时,您应该注意确保代码遵守所有权规则。
Important: Typically there should be no reason to explicitly ask an object what its retain count is (see retainCount). The result is often misleading, as you may be unaware of what framework objects have retained an object in which you are interested. In debugging memory management issues, you should be concerned only with ensuring that your code adheres to the ownership rules.
这里是真正的问题:你为什么需要知道?
So here's the real question: why do you need to know?
这篇关于如何获取NSObject的引用计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!