Old McStopher
Old McStopher

Reputation: 6349

When does (void)dealloc get called in an AppDelegate?

I understand that instance variables are released in dealloc (as shown below), but when exactly is it called? Are all instance variables released upon app close, or is there an accepted way for them to be deallocated individually as they become unneeded?

- (void)dealloc {
    [fred release];
    [wilma release];
    [barney release];
    [betty release];
    [super dealloc];
}

Upvotes: 3

Views: 4583

Answers (1)

Caleb
Caleb

Reputation: 124997

Like any other object, the app delegate will be deallocated when no other object has retained it. It's pretty unusual to have an app delegate that doesn't stick around until the app terminates, and as others have pointed out, the app may not bother to release and deallocate anything just before it exits.

I think it's a safe bet that the app delegate would be deallocated if no object other than the app had retained it and you gave the application a new delegate. Aside from that unusual situation, the app delegate's -dealloc method probably doesn't get called very often at all. However, that doesn't mean that you shouldn't implement it correctly -- it's expected behavior, and things could easily change in a future iOS release.

Upvotes: 7

Related Questions