从未使用的Bitmapsources释放内存

时间:2015-10-28 11:53:10

标签: wpf vb.net image-processing memory-leaks

我尝试通过以下代码将.RAW文件中的大图像加载到System.Windows.Controls.Image中:

Dim pf As PixelFormat = PixelFormats.Gray16
Dim rawStride As Integer = Convert.ToInt32((Convert.ToInt32(RAWImage.ImageSize.Width) * pf.BitsPerPixel + 7) \ 8)
bitmap = BitmapSource.Create(Convert.ToInt32(RAWImage.ImageSize.Width), Convert.ToInt32(RAWImage.ImageSize.Width), 96, 96, _
                                                         pf, Nothing, ImagePixelvalues, rawStride)
MainPictureBox.Source = bitmap

其中ImagePixelvalues是uint16()。 我的问题是由bitmapsource引起的内存泄漏。如果我在图像控件中加载例如100倍RAW图像,则Windows任务管理器性能显示系统的物理内存会在一段时间后增加。这意味着之前的bitmapsource未发布,GC无法收集它们。请让我知道您对此的想法我如何发布bitmapsource

1 个答案:

答案 0 :(得分:0)

当您使用每个位图完成后,您可以尝试

(write arab_roman_dp :stream stream :escape nil :readably nil :pretty nil)
相关问题