. Garbage Collection in net

Source: Internet
Author: User
Tags garbage collection reference valid
The full name of the GC is garbage collection, the Chinese name Garbage collection, which is a function of. NET for memory management. The garbage collector tracks and reclaims objects allocated in managed memory and periodically performs garbage collection to reclaim memory allocated to objects that do not have a valid reference. The GC automatically occurs when the memory request is not satisfied with available memory.


The full name of the GC is garbage collection, the Chinese name Garbage collection, which is a function of. NET for memory management. The garbage collector tracks and reclaims objects allocated in managed memory and periodically performs garbage collection to reclaim memory allocated to objects that do not have a valid reference. The GC automatically occurs when the memory request is not satisfied with available memory.

When garbage collection is done, the garbage collector searches the managed object in memory first, then searches for the referenced object from managed code and marks it as valid, then releases the object that is not marked as valid and reclaims the memory, and finally collates the memory to move the valid objects together. This is the four steps of the GC.

From the above, GC is very bad for performance, so generally this kind of thing is still as good as possible.

To reduce some of the performance impact,. NET GC Support object Aging, or the concept of generational, generation is the object in memory relative to the current period of measurement units, the object's algebra or the existence of time to describe the generation of objects. Current. NET's garbage collector supports three generations. Each time a GC is made, objects that are not recycled automatically ascend a generation. Objects that are created more recently belong to newer generations, which are lower than the algebra of objects created earlier in the application life cycle. Objects in the most recent generation are located in the 0 generation. At each GC time, the objects in the 0 generation are recycled first, and the higher algebra objects are recycled only if the lower algebraic objects are not satisfied with the requirements after the collection is complete.



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.