Skip to content
AtomicReps

Navigation

10/29Computer Science

C# Memory & Types.

Where C# values live, when they are copied, and what the runtime does with them afterwards.

  • C# Memory & Types · 1 of 3

    Struct layout

    What does an empty value type still take?

  • C# Memory & Types · 2 of 3

    Garbage collection

    What does a large allocation skip?

  • C# Memory & Types · 3 of 3

    Weak references

    A memory leak hunt finds objects alive that only a weak handle should reach. What does the measurement point at?

    typescript
    static WeakReference<List<int>> Make() => new WeakReference<List<int>>(new List<int> { 1, 2 });var w = Make();Console.WriteLine(w.TryGetTarget(out var before) + " " + (before?.Count.ToString() ?? "none"));GC.Collect();GC.WaitForPendingFinalizers();GC.Collect();Console.WriteLine(w.TryGetTarget(out var after) + " " + (after?.Count.ToString() ?? "none"));

Three of the 1,100 C# Memory & Types questions.

Keep going with C# Memory & Types, free
Next topic · 11/29C# Programming.