tags:

views:

232

answers:

1

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")))
{
}
+6  A: 

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.

Reed Copsey
ok. My colleagues mentioned that WPF is fully dx accelerated and images , etc are stored in video. Is this just a fantasy ? I am a long time winforms programmer and am now writing a new module in WPF so i assumed i needed to dispose of images.
Andrew Keith
A BitmapSource isn't an image - it's used to generate one. However, it's a managed pixel storage medium. Kind of confusing, but it's always worth checking. In general, just look at the class hierarchy - if it doesn't implement IDisposable, you're free to let the GC worry instead of you. :)
Reed Copsey