I read about CLR in .NET as:
When CLR loads heap is partitioned in SOH and LOH.
-
when application is started at that time heap is allocated by CLR to application depending on its size.
-
LOH heap has Gen0,Gen1,and Gen2 regions.
Here all objects for A class are allocated on Gen0,
Questions
- How CLR knows the size will occupied by application in heap?
-
Suppose there is 4K heap memory allocated by CLR for Gen0 region. Given the code below, is it possible for this single thread to use full 4K memory on Gen0?
collect = new List(); while(true) { collect.Add(new A()); new A(); new A(); } class A { int a = 0, b = 0; }
Gen0and only those which survives while application’s life will be moved toGen1. But it is mentioned that in case whenGen0is full – GC performs garbage collection to clean upGen0and if it is still full – all new objects will be created inGen1.