IOS developer UIViewController Memory Management

Source: Internet
Author: User

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

 
 
  1. -init  
  2. -initWithNibName:bundle: 

Both methods initialize a vc, but note that the view is not loaded at this time.

 
 
  1. -loadView  
  2. -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.

 
 
  1. -view()appear  
  2.  -view()disappear 

These methods are not explained.

 
 
  1. -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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.