[英]Retain Count of a View Controller
I am trying to print the retain count of a view controller in the viewDidLoad method. 我正在尝试在viewDidLoad方法中打印视图控制器的保留计数。 The value returned is 3 . 返回的值为3。
Can someone please tell why is the value 3 ? 有人可以告诉我为什么值3吗?
My code is as follows 我的代码如下
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Retain count in View Did Load is %ld", CFGetRetainCount((__bridge CFTypeRef)(self)));
}
I wouldn't worry about it. 我不会担心。 retainCount
is often temporarily higher than you might expect. retainCount
通常暂时高于您的预期。 Add a -dealloc
method for debugging/unit tests and make sure it is called when the viewController
is dismissed and you'll be fine. 为调试/单元测试添加一个-dealloc
方法,并确保在viewController
时调用该方法, viewController
就可以了。
Well, it's 25 for me: 好吧,对我来说是25岁:
2015-11-18 19:53:51.323 test[61900:10880987] Retain count in View Did Load is 25
You can't rely on the retain count being any particular number (except that it won't be zero). 您不能依赖保留计数为任何特定数字(除非保留数字不会为零)。
If you really want to know how it ended up where it did, use Instruments: 如果您真的想知道它的最终结果,请使用Instruments:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.