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:

12345678910111213 //截取部分图像+(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);        returnsmallImage;}

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.

iOS Performance Tuning series: Analyze Static analysis

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.