ios instruments leak detect memory leaks

When Apple did not release ARC (automatic memory management mechanism), almost half of our development time was spent on managing memory in this way. Later, Apple released ARC very humanly, although to a large extent, it helped our developers save money Energy and time. However, during the development process, due to various reasons, there will still be memory leaks. Memory leaks are a very serious problem. The following is a brief introduction to how to use the Leaks in Xcode8's own Instruments to detect our Whether the program has memory leaks and code for locating memory leaks. (Analysis of memory leaks cannot detect all memory leaks, and some memory leaks are generated during runtime and user operations)

Step 1: Open the Instruments that comes with Xcode8


or:

Or: long press the run button, then the list as shown in the figure appears, click Profile.

According to the above operation, after the build is successful, the Instruments tool will pop out and select the Leaks option

After selection, the interface is as follows:

After getting here, our preparatory work is completed, and the official test will begin!

(There is a point to note, it is best to choose a real machine for testing. The emulator runs on a mac, and there is still a difference between a mac and a mobile phone.)

1. Select Xcode to run the program (command + R) first (if the upper left corner of Xcode already has the instrument icon, you don't need to perform this step)

2. Select Xcode again, press the shortcut key (command + control + i) to run it, and Leaks is already running

3. Since Leaks is a dynamic monitoring, we need to manually operate the APP, and observe the changes of Leaks while operating. When a red cross appears, a memory leak is detected. Click the second one in the upper left corner to pause the detection (or Continue to detect). As shown in the figure:

4. The following is the modification of the positioning. At this time, select the Leaks with the red column, and there is a square with the word "Tian" below it, click it, and select the Call Tree

The following interface is displayed

5. The following is the most critical step. There are several checkboxes in the lower right corner of this interface. Select Invert Call Tree and Hide System Libraries, and the display (within the red circle) is as follows:

Even if it is basically completed here, the memory leak code part is shown here, so there is still one step left: positioning!

6. Select one of the displayed items, double-click, it will automatically jump to the memory leak code, as shown in the figure

7. Find the place where the memory leaks, then we can modify it

After selecting the call tree, you may find that you cannot view the source code and thus cannot locate the location of the memory leak, but only display hexadecimal data. At this point, you need to check whether a dSYM File is generated in Xcode, and select the second item DWARF with dSYM File as shown below.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326685132&siteId=291194637