diff --git a/ARMeilleure/Common/Counter.cs b/ARMeilleure/Common/Counter.cs
index f8c5d2732..8fd73f114 100644
--- a/ARMeilleure/Common/Counter.cs
+++ b/ARMeilleure/Common/Counter.cs
@@ -6,8 +6,9 @@ namespace ARMeilleure.Common
/// Represents a numeric counter.
///
/// Type of the counter
- class Counter where T : unmanaged
+ class Counter : IDisposable where T : unmanaged
{
+ private bool _disposed;
private readonly int _index;
private readonly EntryTable _countTable;
@@ -26,7 +27,18 @@ namespace ARMeilleure.Common
///
/// Gets a reference to the value of the counter.
///
- public ref T Value => ref _countTable.GetValue(_index);
+ public ref T Value
+ {
+ get
+ {
+ if (_disposed)
+ {
+ throw new ObjectDisposedException(null);
+ }
+
+ return ref _countTable.GetValue(_index);
+ }
+ }
///
/// Tries to create a instance from the specified instance.
@@ -64,5 +76,18 @@ namespace ARMeilleure.Common
return false;
}
+
+ ///
+ /// Releases all resources used by the instance.
+ ///
+ public void Dispose()
+ {
+ if (!_disposed)
+ {
+ _countTable.Free(_index);
+
+ _disposed = true;
+ }
+ }
}
}
\ No newline at end of file