启用 ARC 的 iOS 保留计数

标签 ios automatic-ref-counting

<分区>

这是我的代码:

@interface YQViewController ()

@property (nonatomic, strong) UILabel *lb1;

@end

@implementation YQViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    self.title = @"title";

    self.lb1 = [[UILabel alloc]init];

    NSLog(@"retain count is %ld", CFGetRetainCount((__bridge CFTypeRef)self.lb1));

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

如您所见,我将 +alloc-init 发送到 self.lb1,我认为 的保留计数self.lb1 应等于 1,但控制台输出为 2。有人能告诉我原因吗?(ARC 启用,xcode 5,OSX 10.9.1,iOS 7 模拟器)。

最佳答案

如果您正在查找 retainCount 的值,那您就错了。也不异常(exception)。您不能依赖结果值来反射(reflect)代码中发生的事情。

有关详细信息,请参阅 http://whentouseretaincount.com

关于启用 ARC 的 iOS 保留计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22030390/

上一篇:ios - 无法在Appium中使用滚动功能

下一篇:ios - 在 iOS 7 中更改 UITableViewCellStyleValue2 textLabel 的整体 tintColor 和字体大小

相关文章:

ios - UIViewController 未释放

objective-c - ARC是否可以降低我的峰值内存占用量?

ios - Xcode 将图像保存为特定形状

iphone - 类似 Instagram 的刷新按钮

iphone - dequeueReusableCellWithIdentifier 不适用于 ARC 和 IOS 4

c++ - Objective-C:如果我在 ARC 的函数中返回一个 C++ 对象,它会创建一个拷贝吗?我是否必须手动释放该拷贝?

ios - 基于ARC的项目是否可以分析?

ios - 圆形,3 色渐变,动画进度 View

ios - 比较两个集合中的对象

ios - 警告 : Attempt to present <ResetSigninDetailsViewController: 0x8ca9640> on <UINavigationController: 0x8ca44f0> while a presentation is in progress