IOSDevelopmentUIViewController memoryManagement is the content to be introduced in this article.IOSAfter 3.0,UIViewControllerA method called viewDidUnLoad is added. Many people do not know the specific significance of this method. Apple's document simply explains "Called when the controller's view is released from memory, and ask you to clear the view bound to the IBOutlet. Why?
Let's take a look at it first.UIViewControllerSeveral functions from creating a view to displaying a process
- -init
- -initWithNibName:bundle:
Both methods initialize a vc, but note that the view is not loaded at this time.
- -loadView
- -viewDidLoad
When a view is ready to be displayed, vc first checks whether the view has been created. Otherwise, it initializes the view through the previously specified xib file and binds other relationships (if the xib file is not specified, by default, xib with the same name as vc will be searched. For example, myNameViewController will search for myNameViewController. xib file)
If there is no xib file, you can manually create the view required by viewControoler in loadview. The next step is to call-viewDidLoad. Many people like to do other things here, such as making an http request and creating an array. If not,-When viewDidUnload is activatedMemoryIt is easy to leak, as mentioned later.
- -view()appear
- -view()disappear
These methods are not explained.
- -viewDidUnload
This method isMemoryWarning: The view is not called when the current interface is displayed. The view of the controller has been released and assigned as nil.
Next, you need to release the sub-view of the instance variables (IBOulet and added by yourself) and other instance variables, such as the data array and http request of the instance in-viewDidLoaded.
Because when the viewController is activated again to prepare for display (for example, navigationControler returns to the upper level), vc finds that its view is empty and repeats the previous process until the view is created. If you do not release the added sub-views and instance variables, the sub-views are created again.
So,MemoryLeaked.
Summary: DetailsUIViewController memoryI hope this article will be helpful to you.