0

我解析KML文件顯示的路線,但我跑出的內存和應用程序可以終止有人幫助我解決這個問題內存泄漏的Windows Phone

public void DisplayRoute(int i) 
     { 
      content = new KmlContent(); 
      info = Application.GetResourceStream(new Uri("/AppStudio;Component/Resources/kml", UriKind.Relative)); 
      data = content.DeserializeKml(info.Stream); 
      if (data.Document.Placemarks[i].LineString != null) 
       { 
         routeQuery = new RouteQuery(); 
         routeQuery.Waypoints = content.ParseLocation(data.Document.Placemarks[i].LineString.Coordinates); 
         routeQuery.QueryAsync(); 
         routeQuery.QueryCompleted += routeQuery_QueryCompleted; 
       } 
      else 
      { 
       return; 
      } 
     } 

     int count = 0; 
     public void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e) 
     { 
      if (e.Error == null) 
      { 
       Route MyRoute = e.Result; 
       MapRoute mappedRoute = new MapRoute(MyRoute); 
       MainMap.AddRoute(mappedRoute); 
       MainMap.SetView(mappedRoute.Route.BoundingBox); 
       routeQuery.Dispose(); 
       count++; 
      } 
      DisplayRoute(count); 
     } 

用於顯示路由的第一次運行,當我導航到開始頁面,然後回到地圖我用盡內存

回答

3

問題是,你永遠不會釋放你從Application.GetResourceStream得到的流。更改您的代碼爲

using (info = Application.GetResourceStream(new Uri("/AppStudio;Component/Resources/kml", UriKind.Relative))) 
{ 
    //rest of the code using info variable 
} 
+0

我這樣做,但它沒有幫助我仍然遇到同樣的問題。 –

+0

KmlContent類通過任何機會實現IDisposable,所以你將能夠做到這一點呢? –

+0

沒有它處理所有內部連接 –