public void RetainCyclesExpectedTest() { var cache = new IntPtr [totalTestObjects]; MyParentView.noweakcount = 0; for (int i = 0; i < totalTestObjects; i++) { var parent = new MyParentView(useWeak: false); parent.TouchButton(); cache [i] = parent.Handle; } GC.Collect(0); GC.Collect(); GC.WaitForPendingFinalizers(); Assert.That(MyParentView.noweakcount, Is.EqualTo(totalTestObjects), "Retain cycles expected"); for (int i = 0; i < totalTestObjects; i++) { using (var parent = Runtime.GetNSObject <MyParentView> (cache[i])) { var child = (MyButton)parent.Children [0]; child.RemoveStrongRef(); } } }
public void NoRetainCyclesExpectedTest() { var thread = new Thread(delegate() { MyParentView.weakcount = 0; for (int i = 0; i < totalTestObjects; i++) { var parent = new MyParentView(useWeak: true); parent.TouchButton(); } }); thread.Start(); thread.Join(); GC.Collect(0); GC.Collect(); GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers(); TestRuntime.RunAsync(DateTime.Now.AddSeconds(30), () => { }, () => MyParentView.weakcount < totalTestObjects); Assert.That(MyParentView.weakcount, Is.LessThan(totalTestObjects), "No retain cycles expected"); }