using System.Runtime.CompilerServices; var owner = new Holder(); GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true); Console.WriteLine($"owner-before:{GC.GetGeneration(owner)}"); Install(owner); GC.Collect(0, GCCollectionMode.Forced, blocking: true); Console.WriteLine($"child-alive:{owner.Child is not null};child-generation:{GC.GetGeneration(owner.Child!)}"); owner.Child = null; Console.WriteLine($"owner-empty:{owner.Child is null}"); GC.KeepAlive(owner); [MethodImpl(MethodImplOptions.NoInlining)] static void Install(Holder h) => h.Child = new byte[1024]; sealed class Holder { public byte[]? Child; }