Several reasons why Android affects performance

As mobile phones become more and more powerful, many developers have not considered the issue of performance optimization. When the project gets bigger and bigger, memory overflows and crashes various problems. There was a company's backstage before, and as the number of users increased The more users there are server exceptions when using, and the program has problems. For the company, the loss is not only the capital, but also the reputation. Once the reputation is not there, you can't pull it back if you want to, so the performance optimization strategy is very important. That’s more, let’s get to the topic.
In summary, the performance optimization of APP has become a comprehensive quality that developers should have, and it is also a guarantee that developers can complete high-quality application works
due to the sandbox mechanism of Android applications. , The memory size allocated by each application is limited, too low memory will trigger the LMK (Low Memory Killer) mechanism, and then there will be a crash phenomenon. If you want to optimize the memory, you need to understand how java memory is allocated and recycled

Briefly describe from the following aspects:

1.
Android memory management mechanism Android memory management = memory allocation and recycling of
processes, objects, variables Occupied memory: processes, objects, variables

The role of memory management (Android system is divided into 3 levels: linux kernel-->dalvik virtual machine-->appliance framework)
       1. The role of process memory: linux kernel-->appliance framework
       2. The role of object and variable management :dalvik virtual machine

2. Common memory problems
    
Common memory problems are as follows:
           1. Memory leak
           2. Memory jitter
           3. Picture Bitmaprelated
           4. Code quality & quantity

2.1 Memory leak
refers to the phenomenon that after the program applies for memory, when the memory is no longer  needed but cannot be released & returned to the program ,
the impact on the application is
likely to cause memory overflow in the application, namely OOM

  • The essential reason for the memory leak
    1.
    2.StaticThe member variable modified by the collection class keyword
    3. The non-static inner class / anonymous class
    4. The resource object is not closed after use

2.2 Memory jitter
refers to the phenomenon that the memory size keeps floating
2.2.1 Reason: The program frequently allocates memory & garbage collection mechanism (GC) frequently reclaims memory (a large number of temporary small objects are frequently created)
2.2.2 Consequence: garbage collection mechanism (GC) frequent Reclaiming memory can cause lag and even out of memory (OOM).The
         frequent creation of a large number of temporary small objects can cause memory fragmentation, so that when memory needs to be allocated, although there is still remaining memory allocation overall, when these memory are not continuous. , Resulting in the inability to allocate the whole block, the system considers that the memory is insufficient, resulting in memory overflow OOM

 2.3 Image- Bitmaprelated
Android system has limited memory allocated to each application, and image resources consume memory (Bitmap). In many cases, the memory occupied by images is most of the entire APP memory. If Bitmao is used, memory management Slightly improper, it may cause memory overflow, (OOM), easy to cause application crash

2.4 Code quality & quantity
The quality of the code itself (such as data structure, data type, layout, rendering, animation, etc.) & quantity (the size of the code) may cause a lot of memory problems, such as large memory usage, low memory utilization, etc.
      

 

 

 

 

 

 


 

Guess you like

Origin blog.csdn.net/shu_quan/article/details/109237263