iOS Performance optimizations: Instruments

Source: Internet
Author: User

Detecting memory leaks: leaks in instruments

Objective

If you want to detect a memory leak, we will use the leaks tool in the XCODE7 instruments to detect.

The current development environment is arc, so there are few memory leaks. But we must keep good code of the normative. For example: Use notification, do not forget to remove; Use Presentviewcontroller to eject the new controller, don't forget dismiss and so on.

If a memory leak occurs, a third-party framework is typically imported into C. Or a class using C in your project creates an object without manually releasing the object; For example, quartz2d drawing

          

1. Get the graphics context      cgcontextref ctx=uigraphicsgetcurrentcontext ();     2. Drawing//2.1 Create a path to a straight line drawing//Note: Any value created with the Creat/copy/retain method in quartz2d must be released      Cgmutablepathref path= Cgpathcreatemutable ();//2.2 add the drawing information to the path      cgpathmovetopoint (path, NULL, +);      Cgpathaddlinetopoint (Path, NULL, 200, 300);//2.3 add the path to the context//Save the drawing information of the drawing line in the graphical context      Cgcontextaddpath (CTX, path);// 3. Render      Cgcontextstrokepath (CTX);//4. Releases the path created earlier. If you do not write this, you will cause a memory leak      cgpathrelease (path);


How to use leaks:

The first step: Open the XCODE7 instruments

Or:

Click on the above, build successfully jump out of the instruments tool, select the leaks option

After selecting the interface such as:

After we got here, we finished our preparatory work, and started the formal test!

1. Select Xcode to run the program (COMMAND + R) first

2. Select Xcode and press the shortcut key (Command + control + i) to run, and leaks is running.

3. Because leaks is dynamic monitoring, so we need to manually operate the app, while operating, while observing the changes in the leaks, when the Red Fork, the memory leak is monitored, click the second in the upper right corner, for pause detection (also can continue to detect, when more than one pause, one processing more than one).:

4. The following is the positioning modification, at this time to select a red pillar of the leaks, there is a "field" in the box, open, select the call Tree

Display as Interface

5. The following is the most critical step, in the bottom right corner of the interface there are a number of checkboxes, select Invert call Tree and hide System Libraries, (red Circle Range) is shown as follows:

Even if it's basically done here, the memory leak code section is shown here, so now it's one step ahead: Locate!

6. Select one of the displayed bars and double-click to automatically jump to the memory leak code,

7. Where the memory leaks are found, then we can modify them

iOS Performance optimizations: Instruments

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.