Skip to content

Commit 90df4e0

Browse files
authored
Remove incorrectly-coded finalizer in DnnRetrainTransformer (#4754)
1 parent be4b42d commit 90df4e0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Microsoft.ML.Vision/DnnRetrainTransform.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ namespace Microsoft.ML.Transforms
3737
/// <summary>
3838
/// <see cref="ITransformer" /> for the <see cref="DnnRetrainEstimator"/>.
3939
/// </summary>
40-
internal sealed class DnnRetrainTransformer : RowToRowTransformerBase
40+
internal sealed class DnnRetrainTransformer : RowToRowTransformerBase, IDisposable
4141
{
42+
private bool _isDisposed;
43+
4244
private readonly IHostEnvironment _env;
4345
private readonly string _modelLocation;
4446
private readonly bool _isTemporarySavedModel;
@@ -723,13 +725,11 @@ private protected override void SaveModel(ModelSaveContext ctx)
723725
});
724726
}
725727

726-
~DnnRetrainTransformer()
728+
public void Dispose()
727729
{
728-
Dispose(false);
729-
}
730+
if (_isDisposed)
731+
return;
730732

731-
private void Dispose(bool disposing)
732-
{
733733
// Ensure that the Session is not null and it's handle is not Zero, as it may have already been disposed/finalized.
734734
// Technically we shouldn't be calling this if disposing == false, since we're running in finalizer
735735
// 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)
747747
{
748748
DeleteFolderWithRetries(Host, _modelLocation);
749749
}
750+
751+
_isDisposed = true;
750752
}
751753
}
752754

0 commit comments

Comments
 (0)