Skip to content

Commit

Permalink
Remove incorrectly-coded finalizer in DnnRetrainTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jan 16, 2020
1 parent 6eccc35 commit 77f95c3
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit 77f95c3

Please sign in to comment.