IOS Performance Tuning series: use Allocation to dynamically Analyze memory usage and optimize allocation

Source: Internet
Author: User

IOS Performance Tuning series: use Allocation to dynamically Analyze memory usage and optimize allocation

Hardware wide: article 3 of the IOS Performance Tuning series, which is continuously updated.

IOS Performance Tuning series: Analyze static analysis describes how to use static analysis to find IOS memory leaks. IOS Performance Tuning series: using Instruments to dynamically Analyze memory Leaks explains how to use the Leaks tool of Instruments to dynamically Analyze memory Leaks.

These two articles focus on Memory leakage, which is the first aspect of memory optimization.

In addition to memory leakage, memory usage may be unreasonable, which may cause IOS memory warnings.

Unreasonable use of memory is often more difficult to find than memory leakage. Memory leakage can be judged by more tools. The unreasonable use of memory requires developers to analyze the memory based on code and architecture.

Clearly describe the differences between the two:

Memory leakage: memory is allocated, but the program has no pointer to the memory. As a result, the memory cannot be released, resulting in Memory leakage.

Unreasonable Memory usage: Apple officially claims this situation as Abandoned Memory, which is a reference to allocated Memory, but it is not actually used in the program, and other objects are added to the cache, but the objects in the cache have never been used.

The Allocation tool in Instruments provided by XCode can help you understand the memory Allocation. When your App receives a memory warning, you should first use Allocation for memory analysis, understand which objects occupy too much memory.

 

Detailed use of Instruments Allocation

 

Like other tools using Instruments, click the Product menu Profile of XCode to start Instruments:

Select Allocation to automatically start the Allocation tool and IOS simulator:

After the Allocation panel is started, the memory usage curve shows the objects allocated to the current memory, the number of objects, and the functions used to create them.

There are several useful options on the left:

All Objects Created

Created & Still Living

Created & Destroyed

 

Allocation analysis skills

 

The above method can be used to understand the overall memory usage of the application, but the memory warning caused by unreasonable memory usage is often caused by some code or views, we often need to pay attention to the memory Allocation and usage during a certain period of time or operation. Allocation provides this function.

For example, before entering A view or before the operation, we click Mark Generation on the left side of the Allocation panel. At this time, the Generation A node is generated and the current memory condition is displayed:

We can click Mark Generation again after entering the view, and click Mark again after exiting the view. The Generation records before, after, and after entering and closing the view, respectively, the memory of the last Generation should be properly released. Otherwise, it indicates that there is a leak or unreasonable problem in this view or operation.

The above is only the basic application of Allocation. It is complicated to design a set of solutions to use Allocation for rational testing.

 

Record, for better yourself!

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.