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")))
{
}
Call Dispose when you are finished using the Image. The Dispose method leaves the Image in an unusable state. After calling Dispose, you must release all references to the Image so the garbage collector can reclaim the memory that the Image was occupying.
You should dispose it after you have finished with it in the code where this method is called and ignore the warning. Actually, further investigation has revealed that warning to be not as ridiculous as it sounds. It's telling you that bitmap won't be disposed if there is an exception before the method returns.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With