Memory not being relieved when setting BitmapImage to null(将 BitmapImage 设置为 null 时未释放内存)
问题描述
我有一个对象集合,每个对象都包含一个 BitmapImage.我将此集合绑定到 FlipView.当用户在 FlipView 中翻页时,所选对象的 BitmapInmage 从 ApplicationData 加载,我将前一个对象的 BitmapImage 设置为 null 以释放内存.问题是,内存永远不会被释放,并且应用程序在翻转一段时间后崩溃.当我查看集合时,只有实际项目设置了 BitmapImage,所有其他项目都将其设置为 null.那么如何解除记忆呢?
I have a collections of objects, each object contains a BitmapImage. I have this collection bound to a FlipView. When user flips a page in he FlipView, the BitmapInmage of the selected object gets loaded from ApplicationData and I set the BitmapImage of the previous object to null to relieve the memory. The problem is, that the memory never gets relieved and the app crashes after some time of flipping. When I look at the collection, only the actual item has its BitmapImage set, all the others have it as null. So how do I relieve the memory?
我加载图片的方式:
StorageFile s = await ApplicationData.Current.LocalFolder.GetFileAsync(localFilename);
BitmapImage bitmapImage = new BitmapImage();
using (var stream = await s.OpenAsync(FileAccessMode.Read))
{
bitmapImage.SetSource(stream);
}
return bitmapImage;
我认为问题可能是我加载图像的方式,我猜文件流没有被释放
I think the problem may be the way I load the Image, I guess the file stream does not get freed
推荐答案
我在 Windows Phone 7 应用程序中遇到了类似的问题.
I ran into a similar issue with Windows Phone 7 applications.
对我有用的一个技巧是从父元素中删除图像.
One trick that worked for me was removing the image from the parent element.
grid1.Children.Remove(image1);
image1 = null;
我不确定这是否对您的情况有所帮助.
I'm not sure if this will help in your situation though.
我的 博文.
这篇关于将 BitmapImage 设置为 null 时未释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 BitmapImage 设置为 null 时未释放内存
基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01