File tree Expand file tree Collapse file tree
src/TensorFlowNET.Core/Util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,16 +15,22 @@ limitations under the License.
1515******************************************************************************/
1616
1717using System ;
18+ using System . Diagnostics ;
1819using System . Runtime . InteropServices ;
1920
2021namespace Tensorflow . Util
2122{
2223 internal static class SafeHandleExtensions
2324 {
2425 /// <summary>
25- /// Acquires a lease on a safe handle. This method is intended to be used in the initializer of a <c>using</c >
26- /// statement .
26+ /// Acquires a lease on a safe handle. The lease increments the reference count of the <see cref="SafeHandle"/ >
27+ /// to ensure the handle is not released prior to the lease being released .
2728 /// </summary>
29+ /// <remarks>
30+ /// This method is intended to be used in the initializer of a <c>using</c> statement. Failing to release the
31+ /// lease will permanently prevent the underlying <see cref="SafeHandle"/> from being released by the garbage
32+ /// collector.
33+ /// </remarks>
2834 /// <param name="handle">The <see cref="SafeHandle"/> to lease.</param>
2935 /// <returns>A <see cref="SafeHandleLease"/>, which must be disposed to release the resource.</returns>
3036 /// <exception cref="ObjectDisposedException">If the lease could not be acquired.</exception>
@@ -37,8 +43,7 @@ public static SafeHandleLease Lease(this SafeHandle handle)
3743 try
3844 {
3945 handle . DangerousAddRef ( ref success ) ;
40- if ( ! success )
41- throw new ObjectDisposedException ( handle . GetType ( ) . FullName ) ;
46+ Debug . Assert ( success , $ "'{ nameof ( SafeHandle . DangerousAddRef ) } ' does not return when '{ nameof ( success ) } ' is false.") ;
4247
4348 return new SafeHandleLease ( handle ) ;
4449 }
You can’t perform that action at this time.
0 commit comments