Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Microsoft.ML.Vision/DnnRetrainTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ namespace Microsoft.ML.Transforms
/// <summary>
/// <see cref="ITransformer" /> for the <see cref="DnnRetrainEstimator"/>.
/// </summary>
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;
Expand Down Expand Up @@ -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
Expand All @@ -747,6 +747,8 @@ private void Dispose(bool disposing)
{
DeleteFolderWithRetries(Host, _modelLocation);
}

_isDisposed = true;
}
}

Expand Down