我想弄清楚如何释放一个WriteableBitmap内存。WPF WriteableBitmap内存泄漏?
在代码的下一节我填一个WriteableBitmap的的后备缓冲有一个真正的大量“BigImage”(3600 * 4800像素,只是为了测试) 数据。如果我的评论,其中位图和图像都等于行为空,内存不会释放,应用程序消耗〜230 MB,甚至当图像和位图不再使用时,则会消耗 !
正如你可以在代码结束时看到它需要调用GC.Collect()来释放内存。
所以问题是,什么是正确的方式来释放WriteableBitmap对象使用的内存? GC.Collect()是唯一的方法吗?
任何帮助将是伟大的。
PS。对不起,我的英语不好。
private void buttonTest_Click(object sender, RoutedEventArgs e)
{
Image image = new Image();
image.Source = new BitmapImage(new Uri("BigImage"));
WriteableBitmap bitmap = new WriteableBitmap(
(BitmapSource)image.Source);
bitmap.Lock();
// Bitmap processing
bitmap.Unlock();
image = null;
bitmap = null;
GC.Collect();
}
http://stackoverflow.com/questions/1534983/how-to-dispose-a-writeable-bitmap-wpf/2422496#2422496 – nyxtom 2010-03-12 11:29:06