内存泄漏改变图像的Windows Phone 7 [英] Memory Leak changing images in Windows Phone 7
问题描述
我有当我改变多次在Windows Phone 7.5
I have a problem when I change multiple times the image of an Image Container in the Windows Phone 7.5
下面的故障代码的问题:
Here's the faulty code:
public void displayImages() {
image1.Source = new System.Windows.Media.Imaging.BitmapImage
(new Uri("BrainImg/axis/" + axis + currentSlice + ".jpg",
UriKind.RelativeOrAbsolute));
image2.Source = new System.Windows.Media.Imaging.BitmapImage
(new Uri("BrainImg/aseg/" + axis + currentSlice + ".png",
UriKind.RelativeOrAbsolute));
}
private void slider1_ValueChanged(object sender,
RoutedPropertyChangedEventArgs<double> e)
{
// do something
if (this.slider1 != null)
{
currentSlice = (int) this.slider1.Value;
displayImages();
}
}
一些变化(约100我耗尽了内存后, )
After some changes (approximately 100 I ran out of memory)
我已经尝试设置 image.Source
到空
分配新值之前。
I have already tried setting the image.Source
to null
before assigning a new value.
推荐答案
Image控件的默认行为是缓存图片以备将来使用。这意味着,存储器仍然使用由contorl。您需要将引用显式释放的图像以释放内存
The default behaviour of the Image control is to cache the image for future reuse. This means that the memory is still used by the contorl. You need to explicitly release the references to the image to free the memory
这样的:
BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;
更多信息请访问:的 http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips -for - 窗口电话7.aspx
这篇关于内存泄漏改变图像的Windows Phone 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!