我正在解析一个KML文件以显示一条路线,但是我的内存耗尽,应用程序终止可以帮助我解决这个问题
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);
}
第一次运行显示路线,当我导航到起始页面然后回到地图我内存不足
答案 0 :(得分:3)
问题是您永远不会发布从Application.GetResourceStream
获得的流。将您的代码更改为
using (info = Application.GetResourceStream(new Uri("/AppStudio;Component/Resources/kml", UriKind.Relative)))
{
//rest of the code using info variable
}