【发布时间】:2016-01-28 04:25:47
【问题描述】:
我尝试通过以下代码将 .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?
【问题讨论】:
-
你怎么知道BitmapSource负责增加内存消耗?它也可能是您的 ImagePixelvalues。您应该考虑使用内存分析器。
-
你是如何发布图像的?您是在尝试强制 GC,还是尝试了任何技巧(例如:setprocessworkingsetsize)?
-
@Clemens:我将 ImagePixelValue 设为 null,但问题仍然存在。
-
@Caveman:我使用了 GC.Collection() 但没有发生任何事情我对 setprocessworkingsetsize 没有任何影响!!!
标签: wpf vb.net image-processing memory-leaks