.NET garbage collection mechanism two

    GC stands for garbage collection, garbage collection Chinese name, is a feature of the .NET memory management. Garbage collector to track and recover objects managed memory allocated to perform regular garbage collection to reclaim memory allocated to the object referenced is not valid. When the available memory can not satisfy the memory request, GC will automatically.

 

    During garbage collection, the garbage collector will first search for managed objects in memory, and then search for the referenced object from managed code and marked as valid, then the release is not marked as a valid object and recover the memory, the memory will last finishing valid objects move together. This is the four steps of the GC.

 

As seen above, GC is affecting performance, so in general the situation is still such a thing happen as little as possible as well.

 

    In order to reduce some performance impact, aging of objects supported by GC .NET, or generational concept, generation of the object stored in the memory unit of measure relative to the current time, current time or store the algebraic description of the object on behalf of the object belongs. Currently .NET garbage collector supports three generations. Once for each GC, has not been recovered objects will automatically upgrade generation. Objects created closer belong to the newer generations, lower than the algebraic object in the application life cycle created earlier. The object is located in the most recent generation of zero generation. GC every time, are the first generation of zero recycling target, only to be recovered higher algebra in the case only after the completion of the recovery target lower algebra still can not meet demand.

 

Another: can refer to Wang Yonggang article "garbage collection interesting history", see http://www.contextfree.net/wangyg/b/tech_his/gc_history.html

 

 

 

Reproduced in: https: //www.cnblogs.com/200831856/archive/2008/11/28/1343460.html

Guess you like

Origin blog.csdn.net/weixin_34080903/article/details/93711121