Brief Introduction to garbage collection during. Net Runtime

Source: Internet
Author: User
Mark and compressAlgorithm

When the applicationProgramAt startup, a certain number of addresses are allocated to the application. These address spaces are managed heap management heaps used to store object indexes in the application. If you want to add a new object and the Application Management heap does not have enough space, the garbage collection process will be executed.

If the original object is out of the range, the space will be released and a new object will be created. However, if the Garbage Collector cannot release the space, the application will still create the object with an error.

Example: At the beginning of the application, Za has created several objects A, B, C, and D, whose indexes are placed in the management heap.

D

C

B

A

Create an object e in the application lifecycle. Because the management heap does not have enough space to allocate, garbage collection is required. After the last collection, objects A and C are out of the range.

At the beginning of garbage collection, a list of all application objects within the scope is generated. This list includes object B and Object D. The algorithm gradually retrieves the management heap to find objects that are not currently in the list. Once an object out of the range is found, these objects are marked as inaccessible, and the Management heap is compressed. Then place the index of the new object e into the heap.

Generation Concept

In order to improve the efficiency of retrieval heap during garbage collection, this paper proposes the concept of generation. The longer the object is, the less likely it is to be out of range in the heap. Therefore, first retrieve new objects. If you still need space to detect objects that take a long time, this will improve efficiency.

. Net garbage collection supports three generations: generation 0, Generation 1, and generation 2.
Generation 0: the object is the object created during the previous garbage collection;
Generation 1: objects within the scope after a garbage collection;
Generation 2: objects within the range after repeated garbage collection.

During garbage collection, if the space after the 0-on-generation object is not enough to be allocated to the new object, the garbage collector will move to generation 1. If not, the garbage collector will move to generation 2.

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.