Handle memory management with IDisposable