翻看该方法的参考文档,苹果对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中的延迟释放对象,调用这个方法也得不到有用的信息。坑爹的苹果,这方法压根就不是留给我们用的!总之以后大家注意以后不要使用retainCount方法,只要遵守内存管理的规则就够了。