I'm looking through some very old code trying to work out the cause of a long term problem causing from what I can best tell is a memory leak on the server.
I can't seem to wrap my head round what's going on in this method, but suspect the GC.SurpressFinalise()
might be causing issues not releasing some of the memory. Could this be the case?
public class DistributedLock : IDisposable
{
private IRedLock Lock { get; }
private bool Disposed { get; set; }
public bool Acquired => Lock.IsAcquired;
public DistributedLock(string lockKey, TimeSpan expiry)
{
Disposed = false;
var conn = RedLockController.GetConnection();
Lock = conn.CreateLock(lockKey, expiry);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~DistributedLock()
{
Dispose(false);
}
protected virtual void Dispose(bool disposing)
{
if (Disposed) return;
if (disposing)
{
Lock.Dispose();
}
Disposed = true;
}
}