Example #1
0
        public void PinnedBufferIsUnpinnedWhenUnpinnerIsCollected() {
            UnpinWhenGCedTest.Unpinned = false;
            var buffer = new byte[] { 1, 2, 3 };
            var unpinner = new Unpinner(new UnpinWhenGCedTest(GCHandle.Alloc(buffer, GCHandleType.Pinned)));

            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();
            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();

            Assert.IsTrue(UnpinWhenGCedTest.Unpinned);
        }
Example #2
0
        public void PinnedBufferIsUnpinnedWhenUnpinnerIsCollected()
        {
            UnpinWhenGCedTest.Unpinned = false;
            var buffer   = new byte[] { 1, 2, 3 };
            var unpinner = new Unpinner(new UnpinWhenGCedTest(GCHandle.Alloc(buffer, GCHandleType.Pinned)));

            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();
            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();

            Assert.IsTrue(UnpinWhenGCedTest.Unpinned);
        }
Example #3
0
        public void PinnedBufferIsNotUnpinnedWhenUnpinnerIsNotCollected() {
            UnpinWhenGCedTest.Unpinned = false;
            var buffer = new byte[] { 1, 2, 3 };
            var unpinner = new Unpinner(new UnpinWhenGCedTest(GCHandle.Alloc(buffer, GCHandleType.Pinned)));
            var copy = unpinner;
            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();
            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();

            Assert.IsFalse(UnpinWhenGCedTest.Unpinned);
            //unpinner is still in scope
            Console.WriteLine(copy.ToString());
        }
Example #4
0
        public void PinnedBufferIsNotUnpinnedWhenUnpinnerIsNotCollected()
        {
            UnpinWhenGCedTest.Unpinned = false;
            var buffer   = new byte[] { 1, 2, 3 };
            var unpinner = new Unpinner(new UnpinWhenGCedTest(GCHandle.Alloc(buffer, GCHandleType.Pinned)));
            var copy     = unpinner;

            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();
            GC.Collect(3, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();

            Assert.IsFalse(UnpinWhenGCedTest.Unpinned);
            //unpinner is still in scope
            Console.WriteLine(copy.ToString());
        }