【问题标题】:Memory Leak Windows Phone内存泄漏 Windows Phone
【发布时间】:2014-05-03 10:35:48
【问题描述】:

我正在解析 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);
        }

第一次运行时会显示路线,当我导航到起始页面然后返回地图时,内存不足

【问题讨论】:

    标签: c# memory-management windows-phone-8 memory-leaks windows-phone-8-emulator


    【解决方案1】:

    问题是您永远不会释放从Application.GetResourceStream 获得的流。将您的代码更改为

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

    【讨论】:

    • 我这样做了,但它没有帮助我仍然遇到同样的问题。
    • 通过任何机会实现了kmlcontent类,所以你能够与它做同样的事情? span>
    • 不,它会在自己内部处理所有连接
    • 我发现的是在这个forequery.queryAsync()之后内存使用量增加;功能,我在这里处理数百个航点可能是一个原因吗?拆分能解决问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    • 2013-08-23
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    相关资源
    最近更新 更多