寿命长和寿命短的对象之间的区别 [英] Difference between Long Lived and Short Lived objects

查看:470
本文介绍了寿命长和寿命短的对象之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在通过以下URL了解垃圾收集的基本知识

http://msdn.microsoft.com/en-us/library/ee787088.aspx [ ^ ]

在阅读本文期间,Garbage集合对两个不同的对象集(短寿命和长寿命)起作用,这两个对象集分布在各个世代中(第0到第2代).

我无法理解短期和长期对象的含义.如果有人对此提供帮助,这将非常有帮助.

Hi,

I was going through the fundamental of Garbage collection from the following URL

http://msdn.microsoft.com/en-us/library/ee787088.aspx[^]

During going through the article, it became quite prominent that the Garbage collection works on two different sets of objects (Short Lived and Long Lived) which are distributed among Generations (Generation 0 to 2).

I was unable to understand the meaning of Short Lived and Long lived objects. It will be really helpful, if someone helps me out in this.

推荐答案

在Gen-0周期内未发布给GC的对象将被提升为Gen-1. ,并且类似地,如果在下一个Gen-1周期中未将它们释放给GC,则会将它们提升为Gen-2.这些对象通常称为长寿命对象.通常,这些对象在应用程序的整个生命周期中都是活动的.
Objects that are not released for GC during a Gen-0 cycle get promoted to Gen-1, and similarly if they are not released for GC during the next Gen-1 cycle, they are promoted to Gen-2. Such objects are typically referred to as long lived objects. Usually these objects are alive throughout the application''s lifetime.


除了Nish所说的那样,

大多数对象在第0代中被回收以进行垃圾回收,并且不能存活到下一代.

世代1.此世代包含短期对象,并充当短期对象和长期对象之间的缓冲区.

第2代.这一代包含寿命很长的对象.寿命很长的对象的一个​​示例是服务器应用程序中的一个对象,其中包含在整个过程中都处于活动状态的静态数据.

如果条件允许,垃圾收集会在特定的世代进行.收集世代意味着收集该世代及其所有年轻世代的对象.第2代垃圾回收也称为完全垃圾回收,因为它回收了所有世代中的所有对象(即托管堆中的所有对象).
生存和提升在垃圾回收中未回收的对象称为生存者,并被提升到下一代.幸存于第0代垃圾回收的对象将提升为第1代;在第1代垃圾回收中幸存的对象将提升为第2代;和在第二代垃圾回收中幸存下来的对象仍保留在第二代中.
当垃圾收集器检测到某个世代的生存率很高时,它会增加该世代的分配阈值,因此下一个垃圾回收将获得大量的回收内存. CLR始终在两个优先级之间进行权衡:不要让应用程序的工作集变得太大,不要让垃圾回收花费太多时间.".



因此,直到GC2存活下来的所有东西都是长寿的对象.
In addition to what Nish says, as the article suggests,

"Most objects are reclaimed for garbage collection in generation 0 and do not survive to the next generation.

Generation 1. This generation contains short-lived objects and serves as a buffer between short-lived objects and long-lived objects.

Generation 2. This generation contains long-lived objects. An example of a long-lived object is an object in a server application that contains static data that is live for the duration of the process.

Garbage collections occur on specific generations as conditions warrant. Collecting a generation means collecting objects in that generation and all its younger generations. A generation 2 garbage collection is also known as a full garbage collection, because it reclaims all objects in all generations (that is, all objects in the managed heap).
Survival and PromotionsObjects that are not reclaimed in a garbage collection are known as survivors, and are promoted to the next generation. Objects that survive a generation 0 garbage collection are promoted to generation 1; objects that survive a generation 1 garbage collection are promoted to generation 2; and objects that survive a generation 2 garbage collection remain in generation 2.
When the garbage collector detects that the survival rate is high in a generation, it increases the threshold of allocations for that generation, so the next collection gets a substantial size of reclaimed memory. The CLR continually balances two priorities: not letting an application''s working set get too big and not letting the garbage collection take too much time.".



So anything surviving till GC2 is a long-lived object.


这篇关于寿命长和寿命短的对象之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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