/// <summary> /// Pins the object to be allocated by cvSetData. /// </summary> /// <param name="obj"></param> /// <returns></returns> // ReSharper disable once InconsistentNaming protected internal GCHandle AllocGCHandle(object obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (DataHandle.IsAllocated) { DataHandle.Free(); } DataHandle = GCHandle.Alloc(obj, GCHandleType.Pinned); return(DataHandle); }
/// <summary> /// Releases unmanaged resources /// </summary> protected virtual void DisposeUnmanaged() { if (DataHandle.IsAllocated) { DataHandle.Free(); } if (AllocatedMemorySize > 0) { GC.RemoveMemoryPressure(AllocatedMemorySize); AllocatedMemorySize = 0; } if (AllocatedMemory != IntPtr.Zero) { Marshal.FreeHGlobal(AllocatedMemory); AllocatedMemory = IntPtr.Zero; } }