What is the -(void)viewDidUnload is good for?
Could I not just relase everything in -dealloc? If the view did unload, wouldn’t -dealloc be called anyway?
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.
In addition to what has already been indicated, I wanted to elaborate more about logic behind
-viewDidUnload.One of the most important reasons for implementing it is that
UIViewControllersubclasses commonly also contain owning references to various subviews in the view hierarchy. These properties could have been set throughIBOutletswhen loading from a nib, or programmatically inside-loadView, for instance.The additional ownership of subviews by the
UIViewControllermeans that even when its view is removed from the view hierarchy and released to save memory, through which the subviews are also released by the view, they will not actually be deallocated because theUIViewControlleritself still contains its own outstanding retaining references to those objects as well. Releasing theUIViewControlleradditional ownership of these objects ensures they will be deallocated as well to free memory.The objects that you release here are usually recreated and set again when the
UIViewControllerview isre-loaded, either from a Nib or through an implementation of-loadView.Also note that the
UIViewControllerviewproperty isnilby the time this method is called.