更新 手动运行垃圾回收清除内存中,因此,这是不是一个真正的“泄漏”本身我该如何解决这个图像内存泄漏?
我有我通过各种.jpg图像的Web URL的图像浏览器页面。当我使用Windows Phone性能分析工具运行此操作时,每次加载新图像时我使用的内存都会启动starircasing(12张图像让我达到50MB)。我尝试使用此处显示的方法清除图像缓存http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx,但它似乎不起作用。
图像查看器:
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image x:Name="ThumbnailImage" Height="275" Margin="0,0,0,12"/>
</Grid>
后面的代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string imageurl;
if (NavigationContext.QueryString.TryGetValue("imageurl", out imageurl))
{
BitmapImage bitmapImage = ThumbnailImage.Source as BitmapImage;
if (bitmapImage != null)
bitmapImage.UriSource = null;
ThumbnailImage.Source = null;
ThumbnailImage.Source = new BitmapImage(new Uri(imageurl));
}
}
您确定它是内存泄漏吗?尝试在OnNavigatedTo末尾调用GC.Collect()然后调用GC.WaitForPendingFinalizers(),并查看内存消耗是否持续增加。 – 2012-02-06 07:59:26
嗯有趣的GC呼叫清除记忆。我想我的问题应该是:为什么当系统超过90MB时系统不会自动调用垃圾回收? – kbeal2k 2012-02-08 04:02:12