iOS Performance Tuning series: Analyze Static analysis

Source: Internet
Author: User

There are fewer tutorials on iOS performance tuning, and the decision to write an iOS performance Tuning series focuses on several aspects of memory leaks, performance optimization, traffic, and power analysis.

Xcode has provided a very powerful performance tuning tool, combined with several third-party tools and some techniques, to optimize performance very simply.

The first writing is the simplest, analyze static analysis.

When iOS developers build or archive the app, there are a lot of compile warnings that are generated at compile time, and the process of static analysis is similar, and under the Xcode product menu, click Analyze to perform a static analysis of the app.

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.

Analyze Memory leak Analysis:

Declaration errors, logical errors, API call errors are basically warnings at compile time, and the main advantage of analyze is static parsing of memory leaks and code logic errors.

For example, in an arc-enabled environment, enter the following code:

Intercept partial image + (uiimage*) Getsubimage: (unsigned long) uluserheader{    UIImage * sourceimage = [UIImage imagenamed:@] Header.png "];    CGFloat height = sourceImage.size.height;    CGRect rect = CGRectMake (0 + uluserheader*height, 0, height, height);        Cgimageref imageref = Cgimagecreatewithimageinrect ([sourceimage cgimage], rect);    uiimage* smallimage = [UIImage imagewithcgimage:imageref];    Cgimagerelease (imageref);        return smallimage;}

Comment out the line cgimagerelease (IMAGEREF), although arc is opened, it still causes the Imageref object to leak.

Using Analyze for analysis, in the navigation bar Analyze Select Analyzer to view the analysis results:

Analyze has analyzed that the Imageref object has a memory leak, which is not found at compile time.

If you do not use arc, then analyze is more useful.

The other three types of analyze analysis can also be used, which is more explicit than the information given by the compiler.

Analyze Logic Error Monitoring:

This situation is also more difficult to find when Codereview, can use analyze.

As in the code, when tag is not equal to 1, 2, and 3, there will be a problem.

Analyze also gives an arrow tip: Len is a garbage value. It is recommended that the variables be initialized at the same time when declaring them.

Record, for the better of myself!

iOS Performance Tuning series: 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.