From adb1dac60b38f58ac6f19a5933176dfdf1ef7a2b Mon Sep 17 00:00:00 2001 From: FICTURE7 Date: Tue, 13 Apr 2021 14:55:07 +0400 Subject: [PATCH] Make Counter finalizable Most certainly quite an odd use case. --- ARMeilleure/Common/Counter.cs | 46 +++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/ARMeilleure/Common/Counter.cs b/ARMeilleure/Common/Counter.cs index 145eeda08..66ae1c70e 100644 --- a/ARMeilleure/Common/Counter.cs +++ b/ARMeilleure/Common/Counter.cs @@ -41,6 +41,39 @@ namespace ARMeilleure.Common } } + /// + /// Releases all resources used by the instance. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases all unmanaged and optionally managed resources used by the instance. + /// + /// to dispose managed resources also; otherwise just unmanaged resouces + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + // The index into the EntryTable is essentially an unmanaged resource since we allocate and free the + // resource ourselves. + _countTable.Free(_index); + + _disposed = true; + } + } + + /// + /// Frees resources used by instance. + /// + ~Counter() + { + Dispose(false); + } + /// /// Tries to create a instance from the specified instance. /// @@ -77,18 +110,5 @@ namespace ARMeilleure.Common return false; } - - /// - /// Releases all resources used by the instance. - /// - public void Dispose() - { - if (!_disposed) - { - _countTable.Free(_index); - - _disposed = true; - } - } } }