Skip to content

Commit 1af3785

Browse files
committed
Convert Finalize to destructor in Bzip2OutputStream
1 parent 9db3eaa commit 1af3785

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/BZip2/BZip2OutputStream.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ void WriteRun()
482482
/// <summary>
483483
/// Free any resources and other cleanup before garbage collection reclaims memory
484484
/// </summary>
485-
public void Finalize()
485+
~BZip2OutputStream()
486486
{
487487
Close();
488488
}
@@ -493,20 +493,19 @@ public void Finalize()
493493
/// </summary>
494494
public override void Close()
495495
{
496-
if (closed) {
497-
return;
498-
}
496+
if (!closed) {
497+
closed = true;
499498

500-
if (runLength > 0) {
501-
WriteRun();
502-
}
499+
if (runLength > 0) {
500+
WriteRun();
501+
}
503502

504-
currentChar = -1;
505-
EndBlock();
506-
EndCompression();
507-
closed = true;
508-
Flush();
509-
baseStream.Close();
503+
currentChar = -1;
504+
EndBlock();
505+
EndCompression();
506+
Flush();
507+
baseStream.Close();
508+
}
510509
}
511510

512511
/// <summary>

0 commit comments

Comments
 (0)