【问题标题】:iOS retain count with ARC enable [duplicate]启用ARC的iOS保留计数[重复]
【发布时间】:2014-03-28 15:09:57
【问题描述】:

这是我的代码:

@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 模拟器)。

【问题讨论】:

标签: ios automatic-ref-counting


【解决方案1】:

如果您正在查找 retainCount 的值,那么您做错了。也不例外。您不能依赖结果值来反映代码中发生的情况。

详情请见http://whentouseretaincount.com

【讨论】:

猜你喜欢
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多