I’m using the following code many times in my app (especially to manage a NavigationController):
MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
When should I release it ?
Thx for helping,
Stephane
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Don’t. Never release your application delegate – it is managed automatically by the OS.
If you look in your app’s main.m file, you’ll see some code that initializes an instance of
UIApplicationthat represents your app – it is its responsibility to manage the application delegate’s lifecycle, not your responsibility.EDIT as @Goz points out, you should
releaseit if at some point youretainit. However, since the application object (and therefore, by extension its delegate) is guaranteed to remain in scope for the life of the app (unless you go messing with it), it’s far better to simply not do any memory management on the delegate, as this avoids the possibility of accidental over-release or other related issues.