What happens if my object is larger than Gen 0. in .Net?

In an interview, the interviewer asked me the following:

Suppose Gen 0 is 5 kb and the object I create is 20 kb, what will happen?

I replied that the CLR would extend the scope of Gen 0.

Now I'm confused, the correct answer or not.

Is it correct?

+6
source share
6 answers

The exact features are implementation dependent and may vary slightly between framework versions. Gen0 and Gen1 are not designed for growth, and Gen2 can grow indefinitely. Breaking the boundaries of Gen0 and 1 usually causes assembly.

1 0 -, ( ), Gen 1 Gen 0 . , . Gen 2, , ( , ), , , Gen 2.

ETL , , Gen2, Gen2 , .

GC ? , .

+1

Gen 0 25K, - (, , GC, , ).

Gen 0 , 25k ( 256K), . 85K, .

(5K 20K) , - .

+1

LOH 2

, 85K, LOH

2 , 0 1, .

0

, Generations , , , .

0

GC Gen0, Gen1 Gen2. , LOH, 85 .

  • Gen0, , Gen0 85 . 85 , LOH.
  • GC Gen0, Gen1 Gen2, , x86 x64... ,
  • Gen0, Gen1 Gen2 GC GC

, , Gen0, . , GC . Gen0, Gen1 Gen2 GC , . , , , . GC , Gen0, Gen0 , GC Gen0.

, Gen 0 5 kb , 20 , ?

, 5kB Gen0, GC 20 , . GC , Gen0 , . , OutOfMemoryException .

0

gen 0 gen 1.

.NET (SOH).

...

85 (LOH). - . GC, LOH, , .

Source: .NET Red-Gate Article on Memory Management

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

Source: MS docs at GC

-2
source

All Articles