Hard Canton: "iOS Performance Tuning Series" The third, continuously updated, welcome attention.
iOS Performance Tuning series: Analyze static analysis describes how to find iOS memory leaks using the static analysis method, iOS Performance Tuning series: Dynamic analysis of memory leaks using instruments Explains the dynamic analysis of memory leaks using the instruments leaks tool.
These two articles are all focused on memory leaks and are the first areas of concern for memory tuning.
With regard to memory, there may also be an unreasonable use of memory in addition to memory leaks, which can also cause iOS memory warnings.
The irrational use of memory is often more difficult to find than memory leaks, memory leaks can be more aided by tool judgment, and the irrational use of memory requires developers to combine code and architecture for analysis.
Clearly explain the difference between the two:
Memory leak: The memory is allocated, but there is no pointer to that memory in the program, causing the memory to be released, resulting in a memory leak.
Memory unreasonable use: Apple officially said this is abandoned memory, that is, there is a reference to the allocated RAM, but it is not actually used in the program, the object is added to the cache, but the object in the cache has not been used.
The allocation tool in the instruments provided by Xcode can be used to help you understand the allocation of memory, and when your app receives a memory warning, you should first use allocation for memory analysis to see which objects are consuming too much memory.
Instruments Allocation Use detailed
As with other tools that use instruments, click the Xcode Product menu profile to start instruments:
Selecting allocation will automatically start the Allocation tool and the iOS emulator:
After startup, the allocation panel shows the object footprint curves in memory, showing which objects are currently allocated in memory, the number of objects, and what functions were created.
There are several more useful options on the left:
All Objects Created
Created & Still Living
Created & Destroyed
Allocation Analysis Techniques
The above method can be used to understand the overall memory usage of the application, but the memory is not reasonable use caused by some code or view, we often have to focus on the time or the operation of memory allocation and usage, allocation provides this functionality.
For example, before entering a view or before the operation, we click Mark Generation on the left side of the allocation panel, which generates the Generation a node, showing the current situation of the memory:
We can click Mark Generation after entering the view, and then click Mark again after the view exits, so that the three generated Generation record the pre-entry, after-entry, close, and then the last Generation should be properly released. Otherwise, it represents a leak or unreasonable place in this view or operation.
The above is only the basic use of allocation, design a set of use allocation to reasonable test plan is more complex, follow-up slowly introduced.
Record, for the better of myself!
iOS Performance Tuning series: Using allocation to dynamically analyze memory usage