diff --git a/src/TensorFlowNET.Core/Eager/Context.cs b/src/TensorFlowNET.Core/Eager/Context.cs
index 4ee43d35..700e1236 100644
--- a/src/TensorFlowNET.Core/Eager/Context.cs
+++ b/src/TensorFlowNET.Core/Eager/Context.cs
@@ -2,12 +2,10 @@
namespace Tensorflow.Eager
{
- public class Context : IDisposable
+ public class Context : DisposableObject
{
- private IntPtr _handle;
-
- public static int GRAPH_MODE = 0;
- public static int EAGER_MODE = 1;
+ public const int GRAPH_MODE = 0;
+ public const int EAGER_MODE = 1;
public int default_execution_mode;
@@ -17,19 +15,16 @@ namespace Tensorflow.Eager
status.Check(true);
}
- public void Dispose()
- {
- c_api.TFE_DeleteContext(_handle);
- }
+ ///
+ /// Dispose any unmanaged resources related to given .
+ ///
+ protected sealed override void DisposeUnmanagedResources(IntPtr handle)
+ => c_api.TFE_DeleteContext(_handle);
- public bool executing_eagerly()
- {
- return false;
- }
- public static implicit operator IntPtr(Context ctx)
- {
- return ctx._handle;
- }
+ public bool executing_eagerly() => false;
+
+ public static implicit operator IntPtr(Context ctx)
+ => ctx._handle;
}
}
diff --git a/src/TensorFlowNET.Core/Eager/ContextOptions.cs b/src/TensorFlowNET.Core/Eager/ContextOptions.cs
index 4bdf04b3..12c4cdfc 100644
--- a/src/TensorFlowNET.Core/Eager/ContextOptions.cs
+++ b/src/TensorFlowNET.Core/Eager/ContextOptions.cs
@@ -3,23 +3,20 @@ using System.IO;
namespace Tensorflow.Eager
{
- public class ContextOptions : IDisposable //TODO! Eli: Shouldn't this inherieting DisposableObject?
+ public class ContextOptions : DisposableObject
{
- private IntPtr _handle;
+ public ContextOptions() : base(c_api.TFE_NewContextOptions())
+ { }
- public ContextOptions()
- {
- _handle = c_api.TFE_NewContextOptions();
- }
+ ///
+ /// Dispose any unmanaged resources related to given .
+ ///
+ protected sealed override void DisposeUnmanagedResources(IntPtr handle)
+ => c_api.TFE_DeleteContextOptions(_handle);
- public void Dispose()
- {
- c_api.TFE_DeleteContextOptions(_handle);
- }
- public static implicit operator IntPtr(ContextOptions opts)
- {
- return opts._handle;
- }
+ public static implicit operator IntPtr(ContextOptions opts)
+ => opts._handle;
}
+
}