我有一個UIView,當我初始化它已經保持數2,我不明白爲什麼,作爲一個結果,我不能removefromsuperview刪除它保留計數和removeFromSuperview
ViewController.h
@property (nonatomic, retain)FinalAlgView * drawView;
ViewController.m
self.drawView =[[FinalAlgView alloc]init];
NSLog(@"the retain count 1 of drawView is %d", [self.drawView retainCount]);
//the retain count 1 of drawView is 2
[self.bookReader addSubview:self.drawView];
NSLog(@"the retain count 2 of drawView is %d", [self.drawView retainCount]);
//the retain count 2 of drawView is 3
[self.drawView release];
NSLog(@"the retain count 3 of drawView is %d", [self.drawView retainCount]);
//the retain count 3 of drawView is 2
[UIView animateWithDuration:0.2
animations:^{self.drawView.alpha = 0.0;}
completion:^(BOOL finished){ [self.drawView removeFromSuperview];
}];
//do not remove
我不使用ARC
您使用ARC嗎? –
只有一個答案給你的問題:http://stackoverflow.com/questions/4636146/when-to-use-retaincount/4636477#4636477 – rckoenes