Analyze static analysis of iOS performance tuning

Source: Internet
Author: User

Before meeting a colleague wrote old project, need to change the contents of the inside as soon as possible, emergency, let me help. Then help to see it.

And analyze this tool is very useful.

There is a serious memory leak in the project.  Crashes can occur easily if not resolved.  So the initial inspection with Analyze, after the examination, I went, suddenly dumbfounded, unexpectedly there are nearly 300 warnings, and 200 leak memory of the blue warning. That is a change, this can not be casually changed, see the blue warning can not be directly deleted, to see the code first, the analysis of clear logic, it is really useless, can be deleted.

In fact, the most reluctant to change this, belongs to the thankless of life, spent a great deal of energy and a lot of time, in the end boss a look, the page how did not move, is not lazy work?

Will look at the doorway, will not look at the lively. That's right! Boss does not know what you did, so I have been urging you, one after another.

Originally the boss Let the estimated time, that is estimated a time n days.

But the boss said too much, and the decision to compress the time of two-thirds. (I didn't have to estimate that I didn't have to follow the boss's time for half a day.)

What the hell is that supposed to mean? So weekend own home work overtime, anyway overtime also did not pay overtime, simply at home, go to the company also want more fare.

Anyway very bumpy, we do not know maintenance a four or five years ago after a group of people processing and then did not process the results of the project is how to spend time, this aside, let people uncomfortable is doing so much, the boss a look at the page has not changed, said you did not work, and then will scold you a meal, this can save money, You don't have to eat, you just get angry and full.

Fortunately, Analyze comparison can only, do not you go to a one to find where there is a leak, if an estimate for three months is not necessarily able to finish AH.

Here's the Analyze.

The following references from netizens, slightly modified, thanks to share

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.

Analyze static analysis of iOS performance tuning

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.