Document translation-minimizing your app ' s Memory footprint

Source: Internet
Author: User
Tags stack trace

Original Address: https://developer.apple.com/library/ios/technotes/tn2434/_index.html#//apple_ref/doc/uid/DTS40017252
This document is to guide the use of instrument to analyze the memory of the app, Benefit Ah!!!

Optimize your app's memory technology documentation TN2434 optimizing app memory memory is as important as app interactivity and stability. It's not hard to see how the app's memory is different for different devices and systems, and our device memory is limited. Reducing your app's memory footprint is the best way to keep your app running smoothly on your device and avoiding crashes due to low device memory. In addition, using the Memory analysis tool to detect the memory management of the object created by the app can visually show the real-time change of memory. Introduction topic explanation Memory Management Configuration Results Analysis conclusion Introduction to the historical version of the associated data document: This document provides configuration steps for analyzing app memory with Xcode. Analyzing the app's memory at a granular level can sometimes produce amazing results. Further reducing the creation of objects is one of the simplest and most effective ways to keep apps running in a lower memory state. Important: This example is called ASCII man and is a real game project under development. The project is a 2D game based on OpenGL ES, which consumes a lot of memory for rendering the screen. Entry explanation: Memory recording refers to the presence of an object created in the app in the system memory. To configure Xcode:1. Xcode> Project menu >Configuration2. Select Memory Analysis3. Click the Record button4. The navigation area shows the memory footprint: for example, the main thread of the project is occupied or when the front thread occupies5. Keep the app running for a few minutes to ensure that the analysis tool collects some memory data information6. Click the Stop button to stop the analysis. 7. Select a time period for analysis, the results of the analysis will be shown in the following summary area of the table one: Hold down the Command key, click on the figure 1, 2 mark range; Table II: The memory of the object created on behalf of the selected area: Contains the memory of the object that was created when the program was started, The selected time period contains the main memory footprint of the app, which is also the best entry point for memory optimization. It takes time for the description app to create objects and release objects. Reducing the memory of an object during this time period can not only speed up the creation of objects but also provide more memory for the display. 8. Now we're going to analyze your results. "description" This analysis data originates from an app being developed and its memory footprint significantly shows the memory footprint of AP P. Therefore, the following analysis is to illustrate our subject. Its memory may be different from your app, but memory usage and analysis are consistent. Table Three: Display in the Memory object Analysis area: A. The persistence of memory is the focus of this paper's analysis. Shows the total memory currently occupied by the app. That means all the Heap&the Anonymous VM represents an app that consumes memory. What we want to optimize is this part of the memory, the less memory that lasts, the faster the app runs, the less likely the memory warning will be. "Important note" in the Ios,tvos,watchos system, due to the limited memory of the device, the continued high memory of his comrades will cause the app to flash back. B. Continue to occupy another key point. It represents the total number of objects that were created repeatedly. "description" This example shows only two memory analysis indicators, the analysis of other indicators are described in the following documents: User Guide> Memory Analysis Tools >Detailed Indicators Analysis Results analysis: This section is designed to analyze the memory data obtained in the previous section, analyzing app memory consumption as follows: "Important note" The default memory analysis results are presented sequentially in terms of the number of bytes of memory that are continuously occupied. If the results are not sorted in descending order, you can click the arrows to select Descending. 1. Let's look at the first part of memory creation: Table 4: The first part of malloc 96kib. A. The memory space created by this section is 96k. Duplicate creation 144 times resulting in 13.5M of memory occupied, the total memory of the%. B. Click the button to the right to jump to the 144 duplicate created list. Table 5: Now look at where the object was created, in the way that the caller is responsible. "description" Click on the Caller app entry, sorted by caller category, A. The first 10 of the 114 articles are derived from Readimage: method invocation; b. The remaining entries are from Checkandallocate: Method invocation. Table 6: Select the highest call repetition line to analyze the cause of this memory occupancy. Table 7: Shows the creation of objects in the stack queue track. A. Click on the Display right panel button; b. Click "E" to display the extension details; c. View the stack trace and record the method that was called. Table 8: Double-clicking the called method will show the stack trace of the created object. "description" You can see the location in the source code. Displays only the locations in the source code where the memory is occupied and does not show the location in the static library. Table 9: Where to create the object in code: A. The NO. 350 line of code, created by the object occupies 12.56MB of memory space; b. The No. 348 line of code, created by the object occupies 1KB of memory space, can be ignored. Ways to reduce memory creation: Because this line of code accounts for the total memory%. Optimizing this line of code can reduce a lot of memory consumption. A memory slicing method based on geometric projection is used to optimize memory. A. Cancel the creation of memory. Geometric projection-based objects are created in order to create objects quickly and efficiently in the runtime, which is appropriate for situations where memory requirements are not high. Developers should consider using image-based creation. B. Reduce the number of objects created. With varying degrees of image-based masking, developers can also consider reducing the creation of created objects. By monitoring the number of times a duplicate is created, you can reduce the number of objects created by calling methods that repeatedly create objects. C. Reducing the amount of memory space created by a single object reminds developers to optimize app memory by reducing the amount of memory the object occupies. The memory size of the created object is a key factor in memory optimization, and developers can consider removing unnecessary memory usage. 2. Next, analyze the second larger memory footprint. Table 10: Memory Fragmentation A. Back to the display memory creation results panel; b. The second largest memory footprint is the tile class. With each 183-bit occupancy, there is a total of 7.67MB of memory occupied in memory, accounting for the overall.7%. This situation is analyzed by examining the duplicate creation location in the source code. Open memory fragment analysis, in the Edite project in Xcode, you can see 183 bits occupied, the capacity of the array is equal to 7 in operation. Optimized memory analysis: A. In all cases, it is not feasible to remove memory fragments in memory. This is due to the data structure to determine the existence. B. Reducing the number of created objects creating objects is not only determined by the programmer, but the amount of memory fragmentation is largely determined by the designer. Therefore, reducing the number of memory fragments is easier to implement by modifying the project's design. C. Reducing the amount of object memory created for developers to reduce the memory footprint of objects by reducing memory fragmentation, for example:1. The implementation of the red, green, and blue methods requires dynamic rendering. The layer number is 73 methods altogether 21. If the above method is not a method that must be implemented, a developer will consider removing these methods. By removing these methods, you can reduce the memory footprint by nearly 1 m. 2. Animation occupies a large amount of memory, by stipulating that the animation array capacity (less than the default allocation space) can also save us 1.01MB of space. Both of these methods save 2MB of memory for our app, taking up 5 of the total%, and this is just beginning to do memory analysis. Conclusion: This example shows only the two cases that occupy the most. Because we are arranged according to the size of the memory footprint, the first two accounts for nearly total memory%。 The next step is to analyze the remaining 50%occupied. Optimize memory ideas: Remove occupancy, reduce repeat creation times, and reduce the amount of space a single object occupies. Each app has a different memory object, but the analytic approach to optimizing the memory is basically similar. Related resources: Inspire memory-related information, see: User Guide>Analyze app memory usage. Historical version2016.05. atNew document: Use the memory analysis tool to optimize app memory.

My github GitHub

Document translation-minimizing your app ' s Memory footprint

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.