Thanks
Thanks

Reputation: 40329

Will the -dealloc method be called upon application quit?

Apple says, that in Cocoa -dealloc will not be called neccessarily when the application quits. Does this also apply to the iPhone?

Upvotes: 3

Views: 2263

Answers (2)

curtisk
curtisk

Reputation: 20175

I've used the applicationWillTerminate call to perform releases (or [self release]) which then should allow dealloc to try to clean up nicely

Upvotes: 3

Ed Marty
Ed Marty

Reputation: 39690

Yes, it does. If the application is quitting, under certain circumstances, dealloc will not be called. If, for example, anything in applicationWillTerminate takes too long or throws an uncaught exception, the application will quit without calling dealloc.

It may be that it never calls dealloc on quit, since the OS does the memory cleanup anyway. The simplest and quickest solution to find out would be to put a breakpoint on the dealloc of your main view controller and see if it's called on application quit.

I think I remember it wasn't called when I tried this once, but I'm not sure, which is why you should try it yourself.

Upvotes: 3

Related Questions