private static void CreateChildren(Parent parent) { var kids = Enumerable.Range(0, 10) .Select(n => new Child(parent)) .ToArray(); Console.WriteLine("Parent poke children"); parent.RaisePokeChildren(); Console.WriteLine("Kids going out of scope now"); }
private static void Main(string[] args) { var parent = new Parent(); CreateChildren(parent); Console.ReadLine(); // kids are out of scope, yet... Console.WriteLine("Collecting garbage"); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Console.WriteLine("Poking children again"); parent.RaisePokeChildren(); Console.ReadLine(); }
public Child(Parent parent) { _parent = parent; _parent.PokeChildren += ParentPokedMe; }