Records

  • can be class or struct
  • creates methods overrides for enforcing value equality instead of reference equality:
    • Object.Equals
    • Object.GetHashCode
    • operators
      • ==
      • !=
  • implements IEquatable<> parameter
  • implements ToString
  • supports deconstruction
  • supports with expression
  • meant to be immutable

Positional records is a more concise syntax for record:

  • primary constructor parameters match the positional parameters of the record declaration
  • public init-only properties for each parameter

Further read:

https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records#characteristics-of-records

Is it possible to block GC?

We can.

  • for some critical part of application code using GC.TryStartNoGCRegion method.
  • using CER (Constrained Execution Regions) (obsolete)
  • with GC LatencyModes

Further read:

https://learn.microsoft.com/en-us/dotnet/api/system.gc.trystartnogcregion?redirectedfrom=MSDN&view=net-7.0#overloads

https://learn.microsoft.com/en-us/dotnet/framework/performance/constrained-execution-regions?redirectedfrom=MSDN

https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/latency

Garbage Collector

  • automatic memory management
  • allocates and releases memory
  • prevents memory leaks and accessing dead objects
  • provides memory safety
  • virtual memory space
  • defragments/compacts memory
  • heap have 3 generations
    • 0 – for new objects;
    • 1 – for objects that lives through GC from 0
    • 2 – for long living objects from 1 and 0
  • also Large Objects Heap (LOH) for big objects like arrays over 85,000 bytes

Further read:

https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals?source=recommendations