这是我的代码:
@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模拟器)。
答案 0 :(得分:2)
如果您正在查找retainCount
的值,那么您做错了。这没有例外。您不能依赖结果值来反映代码中发生的情况。
有关详细信息,请参阅http://whentouseretaincount.com