我這樣做:檢查保留計數
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainback.jpg"]];
[self.view addSubview:backgroundImage];
NSLog(@" retain count1 : %d " , [backgroundImage retainCount]);
[self.view sendSubviewToBack:backgroundImage];
[backgroundImage release];
NSLog(@" retain count2 : %d " , [backgroundImage retainCount]);
我dealoc功能得到
retain count1 : 2
retain count2 : 1
1)我能得到這樣的消息:
- (void)dealloc{
NSLog(@" retain count2 : %d " , [backgroundImage retainCount]);
[super dealloc];
}
; 2)在最後我得到保留數對於backgroundimage所以它我s ok或應該是0(零) ??
謝謝..
不,你不應該使用它。 爲我節省了解釋它檢查[這一點] [1] [1]:http://stackoverflow.com/questions/4636146/when-to-use-retaincount –