2013-03-11 43 views
0

我的應用程序需要加載圖像從網絡每次提供的類別,它是工作,問題是內存,圖像加載內存不會被刪除當下一類圖像加載,因此內存增加和應用程序以下列消息結束 -窗口手機內存管理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); 

但選擇一些類型的圖像後,它仍然崩潰。

+0

但問題是什麼? – MarcinJuraszek 2013-03-11 06:55:18

+0

如何釋放內存? – Abhishek 2013-03-11 07:14:09

+0

或如何從內存中刪除加載的圖像? – Abhishek 2013-03-11 07:14:42

回答

0

你可以做類似如下:

grid1.Children.Remove(image1); 
image1 = null; 
+0

我已經在網格上添加了圖像,並且在另一個主要網格上添加了該網格;並刪除我used-- grid.Children.Clear(); mainGrid.Children.Remove(grid);但仍然增加內存.. – Abhishek 2013-03-11 07:20:09

+0

你設置圖像對象爲空嗎? – 2013-03-11 07:34:33

+0

grid.children.clear()釋放一些內存是否有任何需要逐步刪除所有圖像和位圖本地對象? – Abhishek 2013-03-11 07:35:24