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; - } - } } }