. Net basics-GC (Garbage Collector)

Source: Internet
Author: User

 

. NetOfFrameworkContains two parts:Bcl(Basic Library),SecondCLR(Public Language Runtime Library ).CLRInGC(Garbage Collector), Also known as the garbage collector.

We should first describe the main points of garbage collection in a formal way:

(1)CLRWhen an object is createdCLRThe memory in the controlled heap is insufficient to create this object, triggeringGCGarbage collection.

( 2 ) wait for all . net only when the application Program is suspended The collection action is not executed immediately and cannot be executed immediately!

( 3 ) Create " whitelist " , at the same time, all objects with the Destructor are placed in the freachable " Red List " (torture before release ).

( 4 ) Start release, the specific form is to " whitelist " the objects in the are uniformly moved to the bottom of the heap, it will be released, and the heap pointer will be updated to the highest available object location.

(5)Now let's take care of some of the redlists,GCExecute the destructor in these objects and reset the destructor"Processed"And then they are waiting for the next cleanup. Before that, these buddies are still in the heap.

The following describes the above steps:

( 1 ) the purpose of creating a destructor for an object is to release unmanaged resources (that is, GC inaccessible CLR , it can be understood as OS resources). Of course, you can also compile dispose () manually releases unmanaged resources, but does not release resources in the heap.

( 2 ) unlike C ++ Use of destructor, . net use as few destructor as possible, because if there are too many destructor, we must call GC recycle to release resources.

( 3 ) WE can encode it as GC to add or reduce memory pressure, you only need to control the collection time.

( 4 ) fully considered GC collection range restrictions, we recommend that you dispose () methods and destructor, of course, we can use the public Code method to ensure that the two do not conflict with each other. In this way, we will obtain flexible processing capabilities.

( 5 ) at the same time, you can set GC some operation features, including whether to disable multi-threaded calling and whether to 2 collect resources by generation.

(6)Stack is divided into three generations:0,1,2Its capacity increases gradually, but its activity degree decreases layer by layer. After each collection,"Whitelist"All of them will be automatically upgraded. Obviously, the higher the level, the longer the proof is, the more likely it will be something global.

 

 

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.