2014-02-26 49 views
0

這裏是我的代碼:iOS的保留與ARC數使

@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-initself.lb1,我覺得self.lb1保留計數應該等於1,但控制檯輸出2.有人可以告訴我原因(ARC啓用,xcode 5,OSX 10.9.1,iOS 7模擬器)。

+1

http://whentouseretaincount.com/ –

回答

2

如果您正在查找retainCount的值,那麼您做錯了。沒有例外。你不能依靠結果值來反映你的代碼中發生了什麼。

有關詳情,請參閱http://whentouseretaincount.com

+0

也包括在的接受的答案http://stackoverflow.com/questions/4636146/when-to-use-retaincount/4636477 #4636477 –

+0

謝謝,我明白了:) – billwang1990