Memory optimization of Android learning

Source: Internet
Author: User

This article is part of the content from http://blog.csdn.net/a396901990/article/details/37914465, thanks to the blogger's sharing, knowledge is very systematic and comprehensive.

These two days in the knowledge of Android memory optimization, Android development is the most prone to the memory leak problem, because the Android memory is limited, and is not very large, which requires developers in the development of the client to pay extra attention to memory optimization, to avoid memory leaks.

So what are the problems that memory leaks cause?

1, the program sluggish, slow response (high memory consumption when the JVM virtual opportunity to trigger the GC frequently)

2, the program inexplicably disappear (when the program occupies a large amount of memory, it is in the background of the more likely to be killed.) Conversely, the smaller the memory footprint, the longer it will exist in the background)

3. Direct Crash (OutOfMemoryError)

The blogger mentioned above, in his blog post on the "5R" method to optimize the memory of Android, "5R" is:reckon (compute), reduce(decrease),reuse (reuse) , Recycle (recycling),Review (check). Some of the tips he mentioned are worth learning from the developers.

Reckon (calculation) I will not detail, interested can go to the above blog to see.

Let me take a look at the parts I used in development and the parts I wanted to learn .

(Here is the list, in the above blog in the detailed introduction of these are, oh, I am listed here is to make their ideas clearer, too much content, I will continue to collate, bigger God's porter. PS: Typography is just annoying)

1. Reduce memory usage (reduce)

(1) Image processing

(2) Use the static final modifier for constants

(3) static method instead of virtual method

(4) Reduction of unnecessary global variables

(5) Avoid creating unnecessary objects

(6) Avoid internal getters/setters

(7) Avoid using floating-point numbers

(8) Using the solid analogy interface good

(9) Use enumeration sparingly

(10) Note for loop

(11) Using the class library

2. Reuse existing resources

(1) Caching usage (cache)

(2) Pool

(3) Adapter (Adapter)

3. Reclaim Unused Memory

(1) Java garbage collection mechanism

(2) Resource Recovery (utility type)

4. Check your own code

(1) UI check (control, layout optimization)

(2) design check (frame, logic optimization)

Memory optimization of Android learning

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.