On which basis it collects objects.
Loading
On which basis it collects objects.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tuhin PaulPosted Jan 25, 2025, 2:04 AM
Part -2
Supporting code in c#:
Mahesh ChandPosted Jan 25, 2025, 1:38 PM
in its simplest form, GC watches memory and use of objects. If your machine is running out of memory, it will look for unused or never used objects and their storage and clears that storage.
Tuhin PaulPosted Jan 25, 2025, 1:45 AM
Part -1
In C#, the Garbage Collector (GC) uses a process called "Mark and Sweep" to identify and clean up objects that are no longer in use. The Garbage Collector primarily uses reachability as the key criterion for collecting objects. An object is considered eligible for garbage collection when it becomes unreachable, meaning:
C# uses a generational garbage collection strategy:
let say there is a memory-intensive application that creates numerous objects rapidly.
Garbage Collection Mechanisms in this Scenario
DataPointobjects quickly usingParallel.For().DataPointinstances) are quickly collectedTo improve performance in scenarios with many object creations:
IDisposablefor large objectsusingstatements for automatic resource managementThe example demonstrates:
GC is triggered when:
GC.Collect()is called (rare and not recommended in production)