Android Garbage Collection

Source: Internet
Author: User

1. When system memory is low, the system activates the memory recycling process. In order not to affect the user experience (such as killing the current active process) due to memory reclamation,

Android based on the components running in the process and their status specifies the default five recycle priority:

Importance_foreground:

Importance_visible:

Importance_service:

Importance_background:

Importance_empty:

  The order of recovery for these priority levels is Empty process, Background process, Service process, Visible process, Foreground process.

2. Prevent memory Overflow:

1) Explicit invocation of System.GC ()

2) bitmap run out with bitmap.recycle ()

3) specify size when image processing

3. First: Do not save references for the context for a long time (to reference the context to make the reference object consistent with its own life cycle).

Second: If you want to use the context, try to use ApplicationContext to replace the context, because the ApplicationContext life cycle is longer, the reference situation will not cause a memory leak problem

Third: Avoid using static variables in your activity when you do not control the life cycle of the object. Try to use WeakReference instead of a static.

IV: The garbage collector does not guarantee the accurate recovery of memory, so that the main life cycle and the timely release of unwanted objects when using what you need. As far as possible at the end of the activity's life cycle, release the other objects we reference in OnDestroy, such as: Cursor.close ().

Android Garbage Collection

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.