diff --git a/src/TensorFlowNET.Core/Sessions/BaseSession.cs b/src/TensorFlowNET.Core/Sessions/BaseSession.cs index 05c593c8..21b0a0a1 100644 --- a/src/TensorFlowNET.Core/Sessions/BaseSession.cs +++ b/src/TensorFlowNET.Core/Sessions/BaseSession.cs @@ -48,6 +48,10 @@ namespace Tensorflow _session = c_api.TF_NewSession(_graph, opts ?? newOpts, status); + // dispose newOpts + if (opts == null) + c_api.TF_DeleteSessionOptions(newOpts); + status.Check(true); } @@ -373,5 +377,19 @@ namespace Tensorflow status.Check(true); } } + + public void close() + { + Dispose(); + } + + protected override void DisposeUnManagedState() + { + using (var status = new Status()) + { + c_api.TF_DeleteSession(_handle, status); + status.Check(true); + } + } } }