diff --git a/src/Microsoft.ML.Vision/DnnRetrainTransform.cs b/src/Microsoft.ML.Vision/DnnRetrainTransform.cs index 54715edf73..b3d8bcff5d 100644 --- a/src/Microsoft.ML.Vision/DnnRetrainTransform.cs +++ b/src/Microsoft.ML.Vision/DnnRetrainTransform.cs @@ -37,8 +37,10 @@ namespace Microsoft.ML.Transforms /// /// for the . /// - internal sealed class DnnRetrainTransformer : RowToRowTransformerBase + internal sealed class DnnRetrainTransformer : RowToRowTransformerBase, IDisposable { + private bool _isDisposed; + private readonly IHostEnvironment _env; private readonly string _modelLocation; private readonly bool _isTemporarySavedModel; @@ -723,13 +725,11 @@ private protected override void SaveModel(ModelSaveContext ctx) }); } - ~DnnRetrainTransformer() + public void Dispose() { - Dispose(false); - } + if (_isDisposed) + return; - private void Dispose(bool disposing) - { // Ensure that the Session is not null and it's handle is not Zero, as it may have already been disposed/finalized. // Technically we shouldn't be calling this if disposing == false, since we're running in finalizer // and the GC doesn't guarantee ordering of finalization of managed objects, but we have to make sure @@ -747,6 +747,8 @@ private void Dispose(bool disposing) { DeleteFolderWithRetries(Host, _modelLocation); } + + _isDisposed = true; } }