Small analysis of Android GC memory recycle

Source: Internet
Author: User

Because of the time problem, simply talk about your own understanding.

As we all know, in Android development, do not need to manage their own, a garbage collection mechanism will automatically help us to recycle

There are no objects that are referenced to.

What exactly is the garbage collection mechanism? Here is a list of some of my understanding.

Garbage-Collected Threads:

It was previously done in the main thread, and later moved to a lower priority.

Previously, a single thread followed by multithreading.

Time for garbage collection:

When the app is idle

When memory is tight

Allocating large chunks of memory is not enough time.

How to recycle:

Does not use generational technology: a one-time GC will traverse all objects, which can be time consuming

The use of generational technology: divided into young generation, the old age, lasting generations. This can put the short life cycle, large and small objects into the young generation

Once a GC can traverse only the younger generation, as long as the freed memory enough can not go through the old age and so on.

Recycling Start:

The garbage collection thread begins the traversal of the object reference from the root set.

The so-called "root Set" is a collection of reference variables that can be accessed in a running thread, such as arguments and local variables for the current function of all threads, member variables of the current class, and so on.

The garbage collection thread first finds all objects that are directly referenced by the root set (called Collection 1).

Then find all the objects that are directly referenced by the collection 1 (called Set 2),

Then find all objects that are directly referenced by Collection 2 ... This repeats itself until all the objects that can be traversed are traversed.

Any object that can be reached from the root set through the above traversal is called a reachable object or a valid object, and conversely, an unreachable object or a defunct object (that is, garbage).

Algorithm for recycling:

Reference count

Labeling method

Object Tree

Monitoring of recycling :

You can override the object Finalize () function. This function is called before the object is recycled.

More information can be found at the following address:

http://hulefei29.iteye.com/blog/658546

Small analysis of Android GC memory recycle

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.