C# › Memory & Garbage Collection

What is the IDisposable pattern and why implement it?

Intermediate

Answer

It provides deterministic cleanup of unmanaged resources via Dispose(), usually with using. Implement it when a type owns unmanaged or disposable resources.
public void Dispose() { _conn.Dispose(); GC.SuppressFinalize(this); }
Real-world example A repository that owns a DbConnection implements IDisposable so callers can release it promptly.