我的應用程序需要加載圖像從網絡每次提供的類別,它是工作,問題是內存,圖像加載內存不會被刪除當下一類圖像加載,因此內存增加和應用程序以下列消息結束 -窗口手機內存管理8
程序'[4036] TaskHost.exe'已退出,代碼爲-2005270523(0x887a0005)。
該代碼是---
空隙webClient_DownloadStringCompleted(對象發件人,DownloadStringCompletedEventArgs E) { 如果(e.Error!= NULL){ timer.Stop(); return; } List rootobj = JsonConvert.DeserializeObject>(e.Result);
int c = 0, x = 0;
for (int i = 0; i < rootobj.Count; i++)
{
Image img = new Image();
img.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
img.VerticalAlignment = System.Windows.VerticalAlignment.Top;
img.Height = 160;
img.Width = 210;
img.Stretch = System.Windows.Media.Stretch.Fill;
BitmapImage bit = new BitmapImage();
string path = rootobj.ElementAt(i).ThumbnailUrl;
bit.UriSource = new Uri(path,UriKind.RelativeOrAbsolute);
img.Source = bit;
img.Margin = new Thickness(x, y, 0, 0);
c++;
if (c == 2)
{
x = 0;
y = y + 160;
c = 0;
}
else
{
x = x + 210;
}
mainGrid.Children.Add(img);
} mainGrid.Children.Add(grid);
}
,併除去我曾試圖these--
for (int i = 0; i < rootobj.Count; i++)
{
Image image = (Image)mainGrid.Children.ElementAt(i);
BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;
bitmapImage = null;
image = null;
}
grid.Children.Clear();
mainGrid.Children.Remove(grid);
但選擇一些類型的圖像後,它仍然崩潰。
但問題是什麼? – MarcinJuraszek 2013-03-11 06:55:18
如何釋放內存? – Abhishek 2013-03-11 07:14:09
或如何從內存中刪除加載的圖像? – Abhishek 2013-03-11 07:14:42