[英]Memory Leak Windows Phone
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 我正在解析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);
}
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 第一次运行时,将显示路线,当我导航到起始页面然后返回到地图时,内存不足
The issue is that you never release the stream you get from Application.GetResourceStream
. 问题是您永远不会释放从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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.