Beispiel #1
0
        public void No_Reference_Allows_GC()
        {
            var obj      = new Object();
            var gcTester = new GCWatch(obj);

            obj = null;

            Assert.IsTrue(gcTester.IsEligibleForGC());
        }
Beispiel #2
0
        public void Usable_Reference_Keeps_Object_Alive()
        {
            var obj      = new Object();
            var gcTester = new GCWatch(obj);

            Assert.IsFalse(gcTester.IsEligibleForGC());

            GC.KeepAlive(obj);
        }
Beispiel #3
0
        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
        }
Beispiel #4
0
        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());
        }