What is garbage collection in .NET?
Garbage collection is automatic managed-memory reclamation performed by the .NET Garbage Collector (GC). It identifies managed objects that are no longer reachable and can reclaim their memory.
C# interview questions covering memory management & modern c#.
Open a question for the full answer, code and interview guidance.
Garbage collection is automatic managed-memory reclamation performed by the .NET Garbage Collector (GC). It identifies managed objects that are no longer reachable and can reclaim their memory.
The .NET GC uses generations to optimize collection based on the observation that many objects have short lifetimes.
IDisposable defines a Dispose method for deterministic cleanup of resources. It is commonly used by types that own unmanaged resources or other disposable resources.
The using statement ensures that an IDisposable object is disposed when execution leaves its scope, including when an exception occurs.
Dispose provides deterministic cleanup and is called explicitly, usually through a using statement or declaration.
Normal value types such as int, bool, and DateTime cannot represent null. Nullable<T>, commonly written with the ? syntax, allows a value type to contain either a normal value or null.
Nullable reference types are a compile-time analysis feature that helps detect possible null-reference problems.
A record is a type designed primarily for data-centric models and provides value-based equality by default.
A class is a reference type and normally uses reference-based equality unless equality is customized. It is appropriate for entities and objects with identity, mutable state, inheritance, or complex behavior.
An init accessor allows a property to be assigned during object initialization but prevents normal reassignment afterward. This supports immutable-style object models.