Skip to content

Commit 52afa42

Browse files
author
David Kline (ANALOG)
committed
update dispose pattern implementation
1 parent 48cd5c8 commit 52afa42

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

Assets/MixedRealityToolkit/Services/BaseService.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,33 @@ public virtual void Destroy() { }
4040

4141
#region IDisposable Implementation
4242

43-
private bool disposed;
44-
43+
/// <summary>
44+
/// Finalizer
45+
/// </summary>
4546
~BaseService()
4647
{
47-
OnDispose(true);
48+
Dispose();
4849
}
4950

51+
/// <summary>
52+
/// Cleanup resources used by this object.
53+
/// </summary>
5054
public void Dispose()
5155
{
52-
if (disposed) { return; }
53-
disposed = true;
56+
// Clean up our resources (managed and unmanaged resources)
57+
Dispose(true);
58+
59+
// Suppress finalization as the the finalizer also calls our cleanup code.
5460
GC.SuppressFinalize(this);
55-
OnDispose(false);
5661
}
5762

58-
protected virtual void OnDispose(bool finalizing) { }
63+
/// <summary>
64+
/// Cleanup resources used by the object
65+
/// </summary>
66+
/// <param name="disposing">Are we fully disposing the object?
67+
/// True will release all managed resources, unmanaged resources are always released.
68+
/// </param>
69+
protected virtual void Dispose(bool disposing) { }
5970

6071
#endregion IDisposable Implementation
6172
}

0 commit comments

Comments
 (0)