Proper way to dispose a BitmapSource

Andrew Keith picture Andrew Keith · Oct 20, 2009 · Viewed 8.8k times · Source

How are you supposed to dispose of a BitmapSource ?

// this wont work because BitmapSource doesnt implement IDisposable
using(BitmapSource bitmap = new BitmapImage(new Uri("myimage.png")))
{
}

Answer

Reed Copsey picture Reed Copsey · Oct 20, 2009

You do not have to Dispose() a BitmapSource. Unlike some other "image" classes in the Framework, it does not wrap any native resources.

Just let it go out of scope, and the garbage collector will free its memory.