简体   繁体   English

保留视图控制器的计数

[英]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.

相关问题 UIViewController pushViewController高保留了View控制器的数量 - UIViewController pushViewController high retain count of View controller 释放消息后,保留视图控制器的计数不等于零 - retain count of a view controller not equal zero after a release message 保留视图控制器 - Retain View Controller 当由于ARC中的保留计数为0而释放视图控制器或与此相关的任何对象时,是否有一种方法可以发出警报? - Is there a way to be alerted when a view controller or any object for that matter is released because of a retain count of 0 in ARC? UIView是否保留其视图控制器 - Does a UIView retain its view controller 使用ARC从Navigation Controller中弹出时,保留View Controller - Retain View Controller when popped from Navigation Controller using ARC 将Viewcontroller添加到Navigation控制器会增加保留计数吗? - Does adding a Viewcontroller to Navigation controller increments the retain Count? UIStoryboardScene意外地取消分配其控制器,而没有更改保留计数 - UIStoryboardScene deallocates its controller unexpectedly without changing retain count iOS-在其上方显示模态后保留View Controller状态 - iOS - retain View Controller state after presenting modal on top of it 弹出另一个视图控制器时如何保留我的nsstring - How to retain my nsstring when popping to another view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM