iOS performance optimization combat--analyze static Analysis

Source: Internet
Author: User

This blog is mainly to study Bo master All-Stack Engineering Lion "iOS Performance Tuning series: Analyze Static Analysis" after the practice, the recent company's project shelves did not do performance tuning, so in this record, in order to use later, in this thank Bo Master All-in-one project Lion wrote the wonderful blog

Analyze mainly analyzes the following four types of problems:

1, logic error: access to null pointers or uninitialized variables, etc.;

2, memory management error: such as memory leaks;

3. Declaration error: A variable that has never been used;

4. API call Error: The libraries and frameworks used are not included.

Problems with the incoming test:

1. Unused variables

2. In an instance method of a class, there is no init on the class to access his member variable appears

instance variable used while ' self ' is not set to the result of [(Super or self) init The code is as follows-(ID) Initwithstyle: (Hzareapickerstyle) Pickerstyle withdelegate: (ID <HZAreaPickerDelegate>) delegate
{
Self = [[[NSBundle Mainbundle] loadnibnamed:@ "Hzareapickerview" owner:self Options:nil] objectatindex:0];
//self = [Super init]; Add this sentence after the OK, and the above sentence can not be replaced with the following sentence, the exchange will appear the same hint, if there is no above this sentence, directly write this sentence will not give the wrong question, but the view is not loaded, there is also written in the If is the same as the issue of the newspaper . According to the analysis here the error is in the first class, that is, the class does not make init must not be able to use his member variables, and the above method is not called the Init method of the class is simply given a property value, here you can see the API document specific previous sentence implementation mechanism. 1. The loaded nib file is actually an XML file, we are designed to be archived, and then called the above method will be archived (during program run time)if (self) {
self.delegate = delegate;
self.pickerstyle = Pickerstyle;
self.locatePicker.dataSource = self;
self.locatePicker.delegate = self;
//Load Data
if (Self.pickerstyle = = hzareapickerwithstateandcityanddistrict) {
provinces = [[Nsarray alloc] initwithcontentsoffile:[[nsbundle Mainbundle] pathforresource:@ "ZH_area.plist "Oftype:nil]];//province,city are declared member variables and set to the method
cities = [[Provinces objectatindex:0] objectforkey:@ "Cities"];
self.locate.state = [[Provinces objectatindex:0] objectforkey:@ "Provincename"];
Self.locate.stateID = [[Provinces objectatindex:0] objectforkey:@ "Provinceid"];
self.locate.city = [[Cities objectatindex:0] objectforkey:@ "CityName"];
Self.locate.cityID = [[Cities objectatindex:0] objectforkey:@ "Cityid"];
areas = [[Cities objectatindex:0] objectforkey:@ "counties"];
if (Areas.count > 0) {
                
self.locate.district = [[Areas objectatindex:0] objectforkey:@ "Countyname"];
Self.locate.districtID = [[Areas objectatindex:0] objectforkey:@ "Countyid"];
} else{
self.locate.district = @ "";
Self.locate.districtID = @ "";
            }
} else{
provinces = [[Nsarray alloc] initwithcontentsoffile:[[nsbundle Mainbundle] pathforresource:@ "ZH_area.plist [Oftype:nil]];
cities = [[Provinces objectatindex:0] objectforkey:@ "Cities"];
self.locate.state = [[Provinces objectatindex:0] objectforkey:@ "Provincename"];
self.locate.city = [[Cities objectatindex:0] objectforkey:@ "CityName"];
        }
    }
        
return self;
} 3. Cgimageref,cgimagesourceref memory leaks are not properly used even in ARC environments (note: ARC is only useful for nsobject)Cgimageref is released using Cgimagerelease, Cgimagesourceref is released using Cfrelease, but remember to make a null judgment4. Forget to call [super ...] when calling some system methods .5. Declare the NSString object in the block, the variable will appear in the instantiation is not referenced in the case, the block inside the declaration is weak, the Amblyopia graph call to report such a workaround, declare a member variable to store the contents of the blockerror message: (Code is changed, no error, write by memory) variable storyed in "variable name" during its initation is never read

iOS performance optimization combat--analyze static Analysis

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.