我有一个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