retainCount不能返回对象真实的被引用的次数
来源:互联网 发布:linux装进u盘 编辑:程序博客网 时间:2024/06/05 13:26
对象的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)
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 内存管理的问题时候,你只要关注保证你的代码符合所有者规则即可。
- retainCount不能返回对象真实的被引用的次数
- 不要用retainCount来获得对象的引用次数
- 不要用retainCount来获得对象的引用次数
- 为什么retainCount返回的对象引用值总是跟预期的不一样呢?
- 不能返回局部对象的引用
- ARC 环境下打印对象的 retainCount 引用计数
- 不能编写返回引用可变对象的访问器方法
- Objective-C中NSString对象的retainCount
- 关于函数不能返回局部对象的引用或者局部对象的指针
- 不能返回局部变量的引用
- 不能返回局部变量的引用
- 千万不能返回局部变量的引用??
- 了解临时对象的来源 (深刻理解为什么不能返回一个临时变量的引用)
- Xcode4.2不能使用 release ,retainCount, retain的解决办法
- Cocoa中retainCount返回值不准的原因
- 为什么不能从子函数中返回临时对象的指针和引用,却可以返回一个临时变量的值
- 返回对象和返回对象的引用的区别
- 函数返回对象和返回对象的引用的区别
- Tuxedo中间件开发和管理
- 微信公众平台开发教程-新手解惑
- 修改UITableViewCell滑动删除按钮标题
- 导航栏常用代码
- 数据库设计
- retainCount不能返回对象真实的被引用的次数
- 查看mysql编码
- iOS 手势并存
- HDOJ 题目1509 Be the Winner(anti-nim)
- iOS开发---网址收藏
- HTML前端ajax请求
- Xcode的Architectures、Valid Architectures和Build Active Architecture Only属性
- Single Round Match 517 Round 1 - Division I, Level Two AdjacentSwaps
- iOS 类别和继承的区别之synthesize not allowed in a category\'s implementation