01-Lazy Loading

Source: Internet
Author: User

Lazy loading, also known as deferred loading, means that during the development process, the resources are not loaded at the start of the program, but are created and loaded when they are used.

iOS devices have limited memory, and if you load all the resources (tablets, data, audio loads, etc.) at the start of the program, it will take up a lot of memory on your device.

--1, custom controls

For custom control properties, you must be a strong type to prevent the control from being destroyed after it has been created because there is no strong pointer pointing.

Such as:

// Default expression content @property (nonatomic,strong) Shemotionlistview * Defaultlistview;

--2, lazy loading in the getter method for attributes

Such as:

-(Shemotionlistview *) defaultlistview{    if (!  _defaultlistview) {        = [[Shemotionlistview alloc] init];         *path = [[NSBundle mainbundle] Pathforresource:@ "emotionicons/default/info.plist"  Oftype:nil];         = [shemotion objectarraywithkeyvaluesarray:[nsarray arraywithcontentsoffile:path];    }     return _defaultlistview;}

Lazy loading is when there is a certain need, and then instantiated into memory.

[Self addSubview:self.recentListView];

Lazy loading the first time the getter method is called, the control is empty before the instantiation is loaded into memory.

The benefits of lazy loading are:

--You do not have to write all the code of the created object in the Viewdidload method, the code is more readable.

--Each property's Getter method is responsible for the respective instantiation processing, and the coupling degree between the code is correspondingly reduced.

--only when resources are really needed, will they be created and loaded, saving memory resources.

  

01-Lazy Loading

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.