Reputation: 1800
I'm parsing a KML file to display a route but I ran out of memory and application terminates can somebody help me solve this problem
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);
}
for the first run the route is displayed, as I navigate to the start page and then back to Map I ran out of memory
Upvotes: 0
Views: 178
Reputation: 16369
The issue is that you never release the stream you get from Application.GetResourceStream
. Change your code to
using (info = Application.GetResourceStream(new Uri("/AppStudio;Component/Resources/kml", UriKind.Relative)))
{
//rest of the code using info variable
}
Upvotes: 3