更新 手動運行垃圾回收清除內存中,因此,這是不是一個真正的「泄漏」本身我該如何解決這個圖像內存泄漏?
我有我通過各種.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