我的程序也发现一个这样的问题,
http://topic.csdn.net/u/20110331/00/9DD6C6E8-6079-4862-851F-1263E9A5E5FB.html搜索了下,很多相关的问题,居然没找到解决方法.相似的代码如下,调用后图片不释放. static class AppHelper
{
public static BitmapImage GetBitmapImage(string path)
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = new MemoryStream(File.ReadAllBytes(path));
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
}
http://topic.csdn.net/u/20110331/00/9DD6C6E8-6079-4862-851F-1263E9A5E5FB.html搜索了下,很多相关的问题,居然没找到解决方法.相似的代码如下,调用后图片不释放. static class AppHelper
{
public static BitmapImage GetBitmapImage(string path)
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = new MemoryStream(File.ReadAllBytes(path));
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
}
Workaround: When dynamically adding or removing BitmapImages from an application (a.k.a. adding/removing from the tree), you should set Image.Source = null before removing the Image element from the tree. This will make the BitmapImage eligible for garbage collection.
Bug Status: Active bug. *
--------------------------------------------------------------------------------
http://blogs.msdn.com/b/silverlight_sdk/archive/2008/10/28/silverlight-bugs-and-workarounds.aspx
http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/46bab672-c65c-4194-96ba-03f3cfc32fa4