3

I have loaded a list of images out of a filestream database. When I load them initially the memory jump isn't that large. When I display them on the screen my memory usage spikes and doesn't go away even after I dispose of the BitmapImage streamsource and set it to Nothing.

    Dim newItem As New MIdentifiedImage
    Dim data As Byte() = dt.Rows(i).Item("ScannedImage")
    Dim strm As New MemoryStream(data)

    Dim bi As New BitmapImage()
    bi.BeginInit()
    bi.StreamSource = strm
    bi.EndInit()
    bi.Freeze()
    newItem.ScannedImage = bi

And here is my dispose code

  For Each img In InvoiceObj.ImageList
    img.ScannedImage.StreamSource.Dispose()
    img.ScannedImage.StreamSource = Nothing

  Next

So my profiler says that the memory usage is low but when I check in my task manager the memory usage is quite high. If I continue to load images beyond 1.5GB of memory it just stops showing the images on screen.

4

1 回答 1

4

您还需要清除ImageList. 只是将其设置StreamSourcenull不会导致它删除已加载的数据。通过ImageList在完成时清除它,您也允许 GC 清理实际BitmapImage实例。

于 2013-10-14T16:41:37.760 回答