Sobes.tech
Junior — Middle

How does garbage collector behavior differ when managing objects of 10 KB and 100 KB?

sobes.tech AI

Answer from AI

In C#, the garbage collector (GC) divides objects into generations (Gen 0, Gen 1, Gen 2) and separately handles large objects (Large Object Heap, LOH).

Objects up to about 85 KB are placed in the regular heap and participate in generational collection. Objects larger than 85 KB are considered large and are placed in the LOH.

Features:

  • Small objects (<85 KB): often created and destroyed, GC collects them more frequently, allowing quick memory release.
  • Large objects (>85 KB): stored in LOH, which is collected less often because operations are more costly.

Thus, 10 KB objects are more frequently collected, while 100 KB objects are collected less often but are more expensive to delete.