During an interview I was asked if there can be some object that will automatically be assigned to second generation of garbage collector and I didn’t know what to answer.
Is this possible?
Maybe if object is large enough to be kept in zero or first generations?
Newly allocated objects form a new generation of objects and are implicitly generation 0 collections, unless they are large objects, in which case they go on the large object heap in a generation 2 collection.
(Link: Fundamentals of Garbage Collection)
So yes, large objects automatically go to generation 2.
When is an object considered large?
In the Microsoft® .NET Framework 1.1 and 2.0, if an object is greater than or equal to 85,000 bytes it’s considered a large object. This number was determined as a result of performance tuning. When an object allocation request comes in and meets that size threshold, it will be allocated on the large object heap. What does this mean exactly? To understand this, it may be beneficial to explain some fundamentals about the .NET garbage collector.
(Link: CLR Inside Out: Large Object Heap Uncovered)