enyim/EnyimMemcached — Issue #84: Using finalizers incorrectly
Author: scarnie
Created: 2011-10-24 17:50:41+00:00
State: open

Enyim is using finalizers / destructors however it does not reference any unmanaged resources. In addition, when implementing the finalizer / IDisposable pattern, there are a few key points to be aware of:

* Only use finalizers if your object references unmanaged resources
* Never access managed resources when called from a finalizer, as they could already be deallocated
* Only call GC.SuppressFinalize when the dispose method is called explicitly

```
class MyObject : IDisposable {
~MyObject() {
this.Dispose(false);
}

public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}

protected void Dispose(bool disposing) {
if (this.disposed) return;

if (disposing) {
// close / cleanup any managed resources
}

// cleanup any unmanaged resources

disposed = true
}
}
```

I can supply a patch soon.