Introduction to the garbage collection mechnism concepts garbage collection mechanism

Source: Internet
Author: User
Traditional garbage collection mechanism
1. Reference count (RC) Algorithm
Before 1960, when people designed the garbage collection mechanism for The LISP Language in the embryo, the first algorithm that came to mind was to reference the counting algorithm. Take napkin as an example.
At lunch, I took out a napkin from my napkin generation and planned to draw a blueprint for the system architecture. According to the requirements of "reference counting edition for napkin use", before drawing a picture, I must write the Count value 1 in the corner of the napkin to indicate that I am using this napkin. This is, if you want to see my napkin too, you must change the napkin count to 2, indicating that two people are using this napkin. After reading it, you must reduce the Count value by 1. Similarly, after I use the napkin, the count on the napkin is changed to 0. At this time, he will be picked up by the garbage collector and thrown into the garbage bin.
The disadvantages and advantages of the reference calculation method are obvious. This algorithm is fast in performing garbage collection tasks, Program Each memory allocation and pointer operation puts forward additional requirements. Importantly, RC cannot correctly release the memory block referenced by the loop.

2. Mark-sweep (MS) Algorithm
Take napkin as an example:
During lunch, all people in the restaurant use napkins as needed. When a garbage collection robot wants to collect used paper napkins, it will stop all diners and then ask each person in the restaurant: "Are you using paper napkins? Which napkin are you using? "The robot marks the napkin that people are using based on their answers. After the inquiry, the robot found all the napkins scattered on the dining table and unlabeled in the dining room and threw them all into the garbage bin.
As its name implies, the execution process of the tag-clearing algorithm is divided into two phases: tag and clear.

3. Copy Algorithm
Cont...

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.