如何找到对象的引用计数 [英] How to find the reference count of an object
问题描述
我想知道程序中某个对象的引用计数.我可以吗?
I want to know the reference count of an object in my program. Can I?
推荐答案
当然:
int referenceCount = rand();
当然,真正的答案是 retainCount
方法;NSUInteger rC = [someObject retainCount];
.但是,它返回的值是没有用的.
The real answer, of course, is the retainCount
method; NSUInteger rC = [someObject retainCount];
. However, the value returned by it is useless.
从不从不在条件中使用保留计数
保留计数永远不能为零
保留计数从不反映对象是否自动释放
the retain count never reflects whether or not the object is autoreleased
在某些时候,对于某些类来说,保留 2-bazillion 的计数是完全合理的
a retain count of 2-bazillion is perfectly reasonable for some classes some of the time
通过系统 API 的任何对象的保留计数可能是一个看似随机的值,表明存在问题
the retain count for any object that passes through system API may be a seemingly random value within indicating a problem
底线:如果您将保留计数视为绝对值,那么您就错了.您可以通过代码增加或减少保留计数,保持优点和缺点的平衡,你就做对了.
Bottom line: If you treat the retain count as an absolute value, you are doing it wrong. You either increase or decrease the retain count through your code, Keep your plusses and minuses in balance, and you are doing it right.
这篇关于如何找到对象的引用计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!