Memory Leak changing images in Windows Phone 7

后端 未结 2 890
小鲜肉
小鲜肉 2021-01-20 20:24

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 displayIm         


        
2条回答
  •  生来不讨喜
    2021-01-20 20:56

    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

    Like this:

      BitmapImage bitmapImage = image.Source as BitmapImage;
      bitmapImage.UriSource = null;
      image.Source = null;
    

    See more at: http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx

提交回复
热议问题