diff --git a/src/TensorFlowNET.Core/Util/SafeHandleExtensions.cs b/src/TensorFlowNET.Core/Util/SafeHandleExtensions.cs index dca0bac3..6594b0b5 100644 --- a/src/TensorFlowNET.Core/Util/SafeHandleExtensions.cs +++ b/src/TensorFlowNET.Core/Util/SafeHandleExtensions.cs @@ -15,6 +15,7 @@ ******************************************************************************/ using System; +using System.Diagnostics; using System.Runtime.InteropServices; namespace Tensorflow.Util @@ -22,9 +23,14 @@ namespace Tensorflow.Util internal static class SafeHandleExtensions { /// - /// Acquires a lease on a safe handle. This method is intended to be used in the initializer of a using - /// statement. + /// Acquires a lease on a safe handle. The lease increments the reference count of the + /// to ensure the handle is not released prior to the lease being released. /// + /// + /// This method is intended to be used in the initializer of a using statement. Failing to release the + /// lease will permanently prevent the underlying from being released by the garbage + /// collector. + /// /// The to lease. /// A , which must be disposed to release the resource. /// If the lease could not be acquired. @@ -37,8 +43,7 @@ namespace Tensorflow.Util try { handle.DangerousAddRef(ref success); - if (!success) - throw new ObjectDisposedException(handle.GetType().FullName); + Debug.Assert(success, $"'{nameof(SafeHandle.DangerousAddRef)}' does not return when '{nameof(success)}' is false."); return new SafeHandleLease(handle); }