The things that IOS didreceivememorywarning

Source: Internet
Author: User

The iOS Uiviewcontroller class gives us an interface to handle out-of-memory interfaces.

Before iOS 3.0, when the system was out of memory, Uiviewcontroller's Didreceivememorywarining method would be called, and we could didreceivememorywarining method to release some temporarily unused resources.

Starting with iOS3.0, Uiviewcontroller added the Viewdidunload method.

This method is paired with the viewdidload.

When the system memory is low, the first Uiviewcontroller didreceivememorywarining method is called, and didreceivememorywarining Determines whether the current Viewcontroller view is displayed on the window,

If it is not displayed on the window, didreceivememorywarining automatically destroys the view of Viewcontroller and all its child view. Then call Viewcontroller's Viewdidunload method .

If the current Uiviewcontroller view is displayed on a window, the Viewcontroller view is not destroyed, and viewdidunload is not called, of course.


ios3-ios5.0 previous version received memory warning:
Calling Super Didreceivememorywarning within Didreceivememorywarning will release the controller's view. So we can't release the controller's view again.
Processing method:

Java code
  1. -(void) didreceivememorywarning
  2. {
  3. [Super didreceivememorywarning]; //If not displayed on window, Self.view will be released automatically.
  4. ///ios6.0 Previously, do not have to do this processing, Self.view release, will call the following Viewdidunload function, in the Viewdidunload function to do the processing.
  5. }
  6. -(void) viewdidunload
  7. {
  8. //Release any retained subviews of the main view. does not contain Self.view
  9. //Handle some memory and resource issues.
  10. [Super Viewdidunload];
  11. }
 


However, after the ios6.0, there has been a change, ios6.0 memory warning Viewdidunload is blocked, that is, back to the ios3.0 period of memory management mode.

ios6.0 and above memory warning:
calls Super didreceivememorywarning view
Processing method:
    -(void) didreceivememorywarning
    {
             [super didreceivememorywarning];//Even if it is not displayed on the window, It will not automatically release the Self.view.
            //Add code to clean up any of your own Resources that is no longer necessary.

            //  Here to do compatible processing need to add ios6.0 macro switch, guaranteed to be used under 6.0, 6.0 blocked the following code before, or will be used below Self.view automatically loaded viewdidunload

if ([[Uidevice currentdevice].systemversion Floatvalue] >= 6.0) {

It is important to note that self.isviewloaded is essential, other ways to access the view will cause it to load, and the WWDC video also ignores this .

if (self.isviewloaded &&!self.view.window)//Is the view being used
{
ADD code to preserve data stored in the "that" might be
Needed later.

ADD code to strong references to the view in
The view hierarchy.
Self.view = nil;//The goal is to re-load the call to the Viewdidload function when it is again entered.
}

}
}

According to the online translation of the understanding is like this. It's not official. I will keep my doubts. Then I found the official link.

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ Viewloadingandunloading.html


What's on IOS didreceivememorywarning

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.