Let's take a look at a problem with IOS Memory leakage.

Source: Internet
Author: User

Let's take a look at a problem with IOS Memory leakage.

Many iOS developers are concerned about memory leakage. In actual development work, we need to know whether the program has memory leakage, and then find out which line of code has leaked memory, in this way, it can be repaired. The simplest method, of course, is to use professional detection tools, such as the BoundsCheck tool, which has very powerful functions.

Memory leakage is related to online stability and performance. Memory leakage may result in the following situation:

1. Online bugs that are difficult to troubleshoot if memory resources are insufficient

2. The existence of the leaked objects may result in some business bugs. For example, the leaked objects are still receiving a global notification.

3. Some performance problems may cause users to become increasingly stuck when using the app

Memory Leak Detection is divided into static scanning and runtime detection. This article focuses on runtime detection.

Static Scan

Common static scanning tools:

Xcode analyzer

OCLint

Infer

Dynamic Detection during runtime

Because static scanning cannot detect all memory leaks, it is an essential operation to detect motion.

Allocation

The Allocation in Xcode can be used to compare objects in different time periods to determine whether memory leakage has occurred. The premise must be that the names of each page must comply with the specifications. For example, all objects on the baby details page are application prefixes + baby details page prefixes + specific object names, when you exit the page, you will know whether the corresponding object is released, because the objects on the bottom page of the stack are often resident in the memory.

Allocation works with Monkey. During regression testing, it runs automatically and calculates the memory usage to determine whether memory leakage has occurred in the new development version, however, you cannot know which object has not been released. The limitation is that you can only make a global decision.

The focus is on troubleshooting?

This is the most critical step when Memory leakage is detected. Based on the leaked objects, developers focus on the final situation of block and two or more objects that are repeatedly referenced.

If ViewController Memory leakage occurs, check whether the block in ViewController has forgotten to declare weak. It is uncommon for ViewController to be held by other objects. Therefore, if RAC is used, we need to remember that weakly and stronugly will appear in pairs; otherwise, memory leakage will occur.

In fact, the most common issue is View memory leakage. First, check whether there is a delegate relationship between views with Memory leakage. If so, check whether the delegate attribute declares weak, generally, memory leakage is caused by asynchronous operations such as service or read cache.

To solve the memory leakage problem, the most important thing is to standardize the code as much as possible. Learning to use tools to troubleshoot is an effective means of accumulating experience. Static scanning can solve some problems, dynamic scanning is the final guarantee.

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.