如果我有如下一个的viewController设置:内存管理&viewDidUnload?
@interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
-(void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
}
,当涉及到内存管理,我应该将释放两个viewDidUnload & dealloc的?
-(void)viewDidUnload {
[locationManager release];
locationManager = nil;
[super viewDidUnload];
}
-(void)dealloc {
[locationManager release];
[super dealloc];
}
欢呼加里
编辑:
[超级的dealloc]移至底部按院长类的意见。
只要注意 - 你应该把[超级dealloc]作为_last_行在你的dealloc方法中。否则,当您尝试释放locationManager时,您可能会遇到崩溃,因为内存可能已经被另一个对象使用。 (非常不可能,但需要注意的地方) – deanWombourne 2010-06-01 14:44:16
谢谢Dean,我的错误,但需要记住的好,再次感谢。 – fuzzygoat 2010-06-01 15:16:52
@dean:如果尚未发布locationManager,那么locationManager的内存如何用于另一个对象? (指发布的原始代码) – progrmr 2010-06-01 16:54:36