Life cycle of UIView in iOS

Source: Internet
Author: User
Tags memory usage

UIView objects are generally created by the Alloc and Init methods and are maintained and managed by Uiviewcontroller. Tasks that you typically need to accomplish are: Create a view, display a view, hide the view, and release the view.

The normal view is not created and loaded immediately when the program is run, and is created only when the application needs this view, and this delay in creating the view can improve the efficiency of memory usage. Again, before this view is needed, the system checks if the view has been loaded, if so, directly returns the created view, and if not, starts the creation process

-(void) Loadview

Executing code during Load view

-(void) viewdidload

View load complete code that needs to be executed

-(void) viewdidunload

Uninstalling View Code

When one view switches to another view, the previous view is not purged and remains in memory waiting for system calls, so a view may appear multiple times during use to uninstall, but only once, that is, call the Loadview and Viewdidload methods once.

Before IOS6, the Viewdidunload method was invoked when the system received the memory warning, and the view was unloaded and emptied. But this method is no longer used after IOS6, as described in the document.

The explanation given here is that the view is no longer erased in low memory. Apple WWDC2012 's farewell statement on this approach

The method Viewwillunload and Viewdidunload. We ' re not going to call them anymore. I mean, there ' s kind of a cost-benifit equation and analysis that we went through. In the early days, there is a real performance need for us to ensure this on memory we warnings our views. There is all kinds the graphics and backing stores and so forth to that would to get also. We now unload those independently of the "view, so it isn ' t" big of "a" deal for us for those to is unloaded, and there W ere so many bugs where there would is pointers into.

Specifically why not need to empty view, the following explains the reason (excerpt from the "Goodbye, Viewdidunload Method")

1.UIView has a Calayer member variable, Calayer is specifically used to draw itself to the screen. As shown in the following illustration:

Related Article

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.