Memory management and viewDidUnload?

If I have a viewController setting as shown below:

@interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
}

-(void)viewDidLoad {
    [super viewDidLoad];
    locationManager = [[CLLocationManager alloc] init];
}

when it comes to memory management, should I add a release to viewDidUnload and dealloc?

-(void)viewDidUnload {
    [locationManager release];
    locationManager = nil;
    [super viewDidUnload];
}


-(void)dealloc {
    [locationManager release];
    [super dealloc];
}

greets gary

EDIT:

[super dealloc] moved down according to Deans kind comment.

+3
source share
3 answers

Short answer:

If you do not create / save it in viewDidLoad (or xib), do not release it in viewDidUnload.

Long answer:

viewDidUnload , - viewDidLoad, IBOutlet, xib . nil in viewDidUnload.

dealloc.

, viewDidUnload , viewDidLoad.

+6

viewDidUnload IBOutlet , viewDidLoad.

, , , . , , IBOutlets, viewDidLoad . , nil viewDidUnload, .

+5

The guy does [issue the object] before doing self.object = nil;

Is the first release for nothing? In the Apple documentation, they just affect zero on a variable ... what's right?

0
source

Source: https://habr.com/ru/post/1747995/


All Articles