Can objects be automatically assigned to the second generation GC?

During the interview I was asked if there could be some object that would be automatically assigned to the second generation of the garbage collector, and I did not know what to answer.

Is it possible?

Maybe if the object is large enough to be stored in zero or the first generation?

+4
source share
1 answer

Recently allocated objects form a new generation of objects and implicitly generate collections 0, unless they are large objects, in which case they go into a bunch of large objects in the generation 2 collection.

(Ref: Basics of garbage collection )

So yes, large objects automatically move on to generation 2.

When is an object considered large ?

In Microsoftยฎ .NET Framework 1.1 and 2.0, if an object is greater than or equal to 85,000 bytes, it is considered a large object. This number was determined by tuning performance. When a request for placement of objects arrives and matches the threshold of this size, it will be allocated to a bunch of large objects. What does it mean? To understand this, it may be helpful to explain some of the basics in the .NET garbage collector.

(Link: CLR Inside Out: A bunch of large objects are not open )

+7
source

Source: https://habr.com/ru/post/1411324/


All Articles