System.Runtime.InteropServices.GCHandle.Free C# (CSharp) Method

Free() private method

private Free ( ) : void
return void
        public void Free()
        {
            // Copy the handle instance member to a local variable. This is required to prevent
            // race conditions releasing the handle.
            IntPtr handle = m_handle;

            // Free the handle if it hasn't already been freed.
            if (handle != IntPtr.Zero && Interlocked.CompareExchange(ref m_handle, IntPtr.Zero, handle) == handle)
            {
#if WIN32
                InternalFree((IntPtr)(((int)handle) & ~1));
#else
                InternalFree((IntPtr)(((long)handle) & ~1L));
#endif

            }
            else
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_HandleIsNotInitialized"));
            }
        }
        

Usage Example

Exemplo n.º 1
0
        public static void FreeString(ref GCHandle handle)
        {
            if (handle == NullHandle)
                return;

            handle.Free();
        }
All Usage Examples Of System.Runtime.InteropServices.GCHandle::Free