iOS performance optimized for locating application memory issues

Source: Internet
Author: User
Tags stack trace

locating the application's memory issues

Managing the memory that your application uses is one of the most important aspects of creating an application. From the smallest iOS device to the largest OS X computer, memory is a limited resource. This chapter describes how to identify common memory problems, from memory leaks to zombies.

Activity Monitor trace template to check memory usage

The Activity Monitor tracking template monitors the overall activity and statistics of the system, including CPU, memory, disk, and network. Simultaneously monitor all existing processes, which can be used to attach a new instrument to a particular process, monitor the parent-child process hierarchy and exit the running process. It consists of active monitoring instruments. You will find later that activity monitor is also used to monitor network activity on iOS devices.

The Activity Monitor tool gives you a visual representation of the information that is quickly and conveniently collected from four charts. These two graphs describe memory usage:

    • the actual amount of memory used (bar chart). shows the first five actual memory of the user in a bar chart.

    • True Memory usage (pie chart). shows the top five actual memory displays the total amount of memory used by the user.

Figure 7-1 The top five user memory systems are displayed.

Figure 7-1 Activity Monitor tools and charts

The following configuration options provide memory-specific information through the activity Monitor. For data definition and complete configuration options , see the Activity Monitor tool in the instrument user Reference .

  • Physical Memory connections

  • Physical Memory Active

  • Physical Memory Not active

  • Physical Memory usage

  • Physical Memory Free

  • Total VM Size

  • VM pages in bytes

  • Bytes on VM

  • Virtual machine switching uses

recover your freed memory in a timely manner

The configuration trace template tracks the actions that are used to allocate heap memory, including specific object-assigned classes. It also records virtual memory statistics by region. It contains the VM assignment and tracking tools.

Avoid discarded memories repeat the same operation repeatedly by ensuring that the heap does not continue to grow. For example, opening a window immediately closes it, or setting a preference for immediate reset is a conceptual operation before returning the application to a stable memory state. Multiple loops through such operations should not cause the heap to grow indefinitely. Make sure that the code does not discard the memory, repeating the user scene, using the Mark generation feature after each iteration. After the first few iterations (the cache may be warm), the persistent memory of these iterations should be reduced to zero. If the persistent memory is still accumulating, select the memory of the call tree of the focus arrows. There you can determine the code path that is responsible for discarding the memory. Make sure your scene exercises all of your code for allocating memory.

find memory and discard your application
    1. Open the configuration template.

    2. Select your app select a target from the pop-up menu 。

    3. Click the Record button.

    4. Repeat an action from the application , and completed, in the same state.

    5. Repeat steps 4 and 5, Until you see whether the heap grows indefinitely, then click the Stop button.

    6. analysis objects are heapshots positioned Discarded memories.

If the heap continues to grow after the first few iterations of the cycle, you know that your application is a memory leak. Finding a heapshot seems to represent a repeat heap growth. Clicking the heapshot name on the right side of the focus button shows that the object scope created during this period still lives in application execution.

After you stop the trace, you can still drag the take photo check header in the Tracking window time to the snapshot you want, and click Mark Generation after generation. After stopping the trace to the last snapshot. At this point, the number of persistent objects should be zero.

Note: garbage collection does not dispose of discarded memory.

find leaks in your application

Measures for leaking trace templates general memory usage, check for memory leaks, and provide statistical data by classes as well as objects allocated by the memory address history all activities allocated and leaked by the neighborhood. It consists of dispensing and leaking instruments.

Use the leak tool to discover that objects in your application are no longer referenced and accessible. The memory leak reporting tool for these blocks. These reports leak objects and class names. Other reports are malloc- size .

Find memory Leaks
    1. open leaking instrument.

    2. Select your app select a target from the pop-up menu 。

    3. Click the Record button.

    4. Workout your application execution code , the leak appears when you click the Stop button.

    5. Click on any leaking object in the determine details pane 。

    6. Click the Xcode icon in the details pane to hit Open the Xcode code.

Note: If the leak is not an object, you can invoke the assumption of ownership of the API -the malloc  memory block you are missing the corresponding free () call.

After opening the block code of Xcode to create a leak, the cause of the leak may still not be clear. The leak tool allows you to see the leakage and root options of the cycle that is being created in the details pane. It provides a reference cycle of the diagram that is causing the leak.

circulation diagram of the leak
    1. Select the leaking instrument.

    2. In the details pane, select Cycle & root.

    3. Select the leak you want to see in the diagram.

Eliminate zombie and zombie tracking templates

Zombie Tracking template measures general memory usage while focusing on overreleased detection, "zombie" objects. It uses the configuration tool to display the history of the data object's assigned classes and all active allocated memory addresses. Note that because the zombie tracking template uses "Debug" mode, many other values show that the configuration tool will not make sense.

Zombie Tracking Template Setting variables NSZombieEnabled come to真正的 instruct the compiler to replace a type of object? NSZombie The reference count for the object being disposed is zero. Send message saying zombie When app crashes, recording stops, Zombie gives dialog box. Click the Focus button to the right of the message dialog box to display the history of the Overreleased object that detects the complete memory of the zombie. Note that this memory history is the only part of the allocation instrument in the use of meaningful zombie tracking templates.

discover Zombies in your code
    1. Open the zombie template.

    2. Select your app to select a target from the pop-up menu.

    3. Click the Record button and run your app.

    4. When a zombie gives a dialog box, click the Message Text dialog box to the right of the attention button.

    5. Open the Extended details pane and double-click the history table for the zombie event type object.

    6. In the stack trace that appears, double-clicking the caller is responsible for displaying the code.

tip: Zombie templates can cause memory growth because the ability to provide any zombie, the information object's memory allocation is never retracted. iOS app that uses it with the iOS emulator instead of the device itself. For the same reason, do not use both zombie templates and leak devices.

iOS performance optimized for locating application memory issues

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.