retainCount不能返回对象真实的被引用的次数

对象的retainCount有时候并不能真正返回对象的被引用次数。

参考:http://blog.csdn.net/wzzvictory/article/details/9626017

http://blog.csdn.net/ahopedog/article/details/7868429


1.

苹果对retainCount方法的描述如下:

retainCount

Do not use this method. (required)

- ( NSUInteger)retainCount
Return Value

The receiver’s reference count.

Special Considerations

This method is of no value in debugging memory management issues.Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

在该方法的特别说明部分苹果解释道:

调试内存管理问题时调用该方法是没有任何意义的。因为保不准Cocoa framework中的其它对象会retain我们的目标对象,还有对于autorelease pool中的延迟释放对象,调用这个方法也得不到有用的信息。


2.

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.
原文:http://stackoverflow.com/questions/2640568/objectivec-how-to-get-the-reference-count-of-an-nsobject
翻译:通 常我们没有必要去特地查询一个对象的retain count是多少。查询的结果常常会出乎意料。你不清楚framework里面的其他对象对你感兴趣的这个对象进行了多少retain操作。在debug 内存管理的问题时候,你只要关注保证你的代码符合所有者规则即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值