什么是垃圾回收的代? [英] What are the Generations in Garbage Collection?

查看:217
本文介绍了什么是垃圾回收的代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白垃圾收集的后代,虽然我发现了一些来自谷歌。你们可有一个人请告诉我关于简单的术语。

I have not understood the generations of Garbage Collection though I found some from google. Can some one of you please tell me in simple terms about that.

或者可以引用一个链接,这将是很容易的理解!

Or can reference to a link which will be easy to understand from !

推荐答案

了解垃圾收集在.NET

一个世代垃圾收集器   收集短命对象的更多   往往比长居住的。   短期对象被存储在   第一代,代0。   长期的对象推入   较高的世代,1或2。   垃圾收集器的工作原理更   经常在较低世代   比在较高的。

A generational garbage collector collects the short-lived objects more frequently than the longer lived ones. Short-lived objects are stored in the first generation, generation 0. The longer-lived objects are pushed into the higher generations, 1 or 2. The garbage collector works more frequently in the lower generations than in the higher ones.

当第一次创建一个对象,它是   投入代0时   0代被填满,垃圾   收集器调用。该对象   生存下来的垃圾收集   第一代被提升到   下一个较高的一代,1。   生存下来的垃圾的对象   集合中的第1代是   推进到下一个和最高   一代,一代2.本   算法能够高效工作   对象的垃圾收集,因为它   快。需要注意的是第2代是   最高的一代人是   由垃圾回收器的支持。

When an object is first created, it is put into generation 0. When the generation 0 is filled up, the garbage collector is invoked. The objects that survive the garbage collection in the first generation are promoted onto the next higher generation, generation 1. The objects that survive garbage collection in generation 1 are promoted onto the next and the highest generation, generation 2. This algorithm works efficiently for garbage collection of objects, as it is fast. Note that generation 2 is the highest generation that is supported by the garbage collector.

垃圾收集在.NET

在内存分配上   托管堆速度快,GC本身   可能需要一些时间。考虑到这一点   几个最佳化已经进行了   以提高性能。在GC   支持几代人的概念,   基于这样的假设   再一个对象已经堆,   时间越长,可能会留下   那里。当一个对象被分配在   堆它属于新一代0。   每个垃圾收集,这一   对象生存增加其   新一代1(目前最高   支持的生成是2)。明显   它的速度更快进行搜索,并   垃圾收集所有的子集   在堆对象,因此,GC有   只收集一代的选择   0,1或2的对象(或任何   组合它选择,直到它有   足够的内存)。即使在   只收集年轻对象的GC   还可以确定是否老物件有   引用新的对象,以确保   它不无意中忽略   在使用的对象。

While memory allocation on the managed heap is fast, GC itself may take some time. With this in mind several optimisations have been made to improve performance. The GC supports the concept of generations, based on the assumption that the longer an object has been on the heap, the longer it will probably stay there. When an object is allocated on the heap it belongs in generation 0. Each garbage collection that that object survives increases its generation by 1 (currently the highest supported generation is 2). Obviously it's faster to search through, and garbage collect a subset of all objects on the heap, so the GC has the option of collecting only generation 0, 1 or 2 objects (or whatever combination it chooses until it has sufficient memory). Even while collecting only younger objects the GC can also determine if old objects have references to new objects to ensure that it doesn't inadvertently ignore in-use objects.

这篇关于什么是垃圾回收的代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆