예제 #1
0
        public void NotFreeTheMemoryAllocatedIfPtrIsZero()
        {
            var target = new StubStructMarshallingService();

            target.FreeHGlobalIfNeeded(IntPtr.Zero);

            Assert.IsFalse(target.ReleasedUnmanagedMemory);
        }
예제 #2
0
        public void FreeTheMemoryAllocated()
        {
            var result = IntPtr.Zero;
            var target = new StubStructMarshallingService();

            try
            {
                result = Marshal.AllocHGlobal(4);
                Assert.AreNotEqual(IntPtr.Zero, result);
            }
            finally
            {
                target.FreeHGlobalIfNeeded(result);

                Assert.IsTrue(target.ReleasedUnmanagedMemory);
            }
        }