public void No_Reference_Allows_GC() { var obj = new Object(); var gcTester = new GCWatch(obj); obj = null; Assert.IsTrue(gcTester.IsEligibleForGC()); }
public void Usable_Reference_Keeps_Object_Alive() { var obj = new Object(); var gcTester = new GCWatch(obj); Assert.IsFalse(gcTester.IsEligibleForGC()); GC.KeepAlive(obj); }
public void Reference_Keeps_Object_Alive_Or_Not() { var obj = new Object(); var gcTester = new GCWatch(obj); #if DEBUG Assert.IsFalse(gcTester.IsEligibleForGC()); #else Assert.IsTrue(gcTester.IsEligibleForGC()); #endif }
public void GC_Collects_Graph() { var foo1 = new Foo(); var foo2 = new Foo(); var gcTester1 = new GCWatch(foo1); var gcTester2 = new GCWatch(foo2); foo1.objects.Add(foo2); foo2.objects.Add(foo1); foo1 = null; Assert.IsFalse(gcTester1.IsEligibleForGC()); Assert.IsFalse(gcTester2.IsEligibleForGC()); GC.KeepAlive(foo2); foo2 = null; Assert.IsTrue(gcTester1.IsEligibleForGC()); Assert.IsTrue(gcTester2.IsEligibleForGC()); }