• <i id='FjIHi'><tr id='FjIHi'><dt id='FjIHi'><q id='FjIHi'><span id='FjIHi'><b id='FjIHi'><form id='FjIHi'><ins id='FjIHi'></ins><ul id='FjIHi'></ul><sub id='FjIHi'></sub></form><legend id='FjIHi'></legend><bdo id='FjIHi'><pre id='FjIHi'><center id='FjIHi'></center></pre></bdo></b><th id='FjIHi'></th></span></q></dt></tr></i><div id='FjIHi'><tfoot id='FjIHi'></tfoot><dl id='FjIHi'><fieldset id='FjIHi'></fieldset></dl></div>

    <legend id='FjIHi'><style id='FjIHi'><dir id='FjIHi'><q id='FjIHi'></q></dir></style></legend>

    <small id='FjIHi'></small><noframes id='FjIHi'>

  • <tfoot id='FjIHi'></tfoot>

        <bdo id='FjIHi'></bdo><ul id='FjIHi'></ul>

        删除 Pages windows phone

        时间:2023-08-28
        <tfoot id='tIjvv'></tfoot>

                  <tbody id='tIjvv'></tbody>
                <i id='tIjvv'><tr id='tIjvv'><dt id='tIjvv'><q id='tIjvv'><span id='tIjvv'><b id='tIjvv'><form id='tIjvv'><ins id='tIjvv'></ins><ul id='tIjvv'></ul><sub id='tIjvv'></sub></form><legend id='tIjvv'></legend><bdo id='tIjvv'><pre id='tIjvv'><center id='tIjvv'></center></pre></bdo></b><th id='tIjvv'></th></span></q></dt></tr></i><div id='tIjvv'><tfoot id='tIjvv'></tfoot><dl id='tIjvv'><fieldset id='tIjvv'></fieldset></dl></div>
                  <bdo id='tIjvv'></bdo><ul id='tIjvv'></ul>

                • <legend id='tIjvv'><style id='tIjvv'><dir id='tIjvv'><q id='tIjvv'></q></dir></style></legend>

                  <small id='tIjvv'></small><noframes id='tIjvv'>

                  本文介绍了删除 Pages windows phone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个大项目,我的应用程序一直保留我导航离开的页面.该页面仅使用最少,并且有很多图形,因此我希望将其从内存中完全删除.

                  I have a big project where my application keeps retaining a page which I navigated away from. The page is only used minimal, and have a lot of graphics, I therefore want it to be completely removed from memory.

                  因此我使用了以下

                   NavigationService.RemoveBackEntry();
                  

                  使用我看到的分析器,上面的代码片段确保我只有 1 个页面实例.但由于它的图形很重,我仍然希望它完全从内存中删除,即分析器中没有实例.

                  Using the profiler I saw that, the above snippet made sure that I would only have 1 instance of the page. But as it is heavy with graphics I still want it to be completely removed from memory, i.e. no instances in the profiler.

                  在我的大型应用程序中,我尝试取消订阅所有事件,引入 dispose/finalize 和调用 GC,它有所帮助,但实例仍然存在.

                  In my big application I tried to unsubscribe to all events, introduce dispose/finalize and calling GC, it helped some but the instance still existed.

                  为了排除任何愚蠢的错误,我制作了 这个小样本.仅使用内存弹出检查器在两个哑页面之间导航.但是仍然存在 1-2 个页面实例.是否有强制删除页面以使其没有任何内容存储在内存中的方法?

                  To exclude any stupid errors, I have made this small sample. Only Navigating between two dumb pages with a memory popup checker. But still 1-2 instances of the pages still exists. Is there anyway to force the removal of pages such that nothing of it is stored in memory?

                  我已添加:

                              while (App.RootFrame.RemoveBackEntry() != null) ;
                  

                  到 OnNavigated to,它会删除除我开始的第一页之外的所有页面.我使用了调试分析工具包,可以看到无论我从哪个页面开始,当我离开它时,它都不会被删除.

                  To the OnNavigated to, and it removes all the pages except the first page I start on. I've used the debug analysis toolkit, and can see that no matter what the first page I start on does not get removed, when I navigate away from it.

                  推荐答案

                  WP Silverlight 运行时将在内存中最多保留三页,即使从后台堆栈中删除也是如此.我仍然不清楚这种行为的原因,但我找到了一个(丑陋的)解决方法:http://blogs.codes-sources.com/kookiz/archive/2013/11/11/wpdev-give-that-memory-back.aspx

                  The WP Silverlight runtime will keep up to three pages in memory, even after being removed from the backstack. The reason for this behavior is still unclear to me, but I've found a (ugly) workaround: http://blogs.codes-sources.com/kookiz/archive/2013/11/11/wpdev-give-that-memory-back.aspx

                  基本上,覆盖页面的 OnNavigatedTo 处理程序,并强制垃圾回收 3 次,通过调用调度程序分开:

                  Basically, override the OnNavigatedTo handler of your page, and force a garbage collection three times, separated by calls to the dispatcher:

                  protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
                  {
                      base.OnNavigatedTo(e);
                  
                      this.Dispatcher.BeginInvoke(() =>
                      {
                          GC.Collect();
                          GC.WaitForPendingFinalizers();
                  
                          this.Dispatcher.BeginInvoke(() =>
                          {
                              GC.Collect();
                              GC.WaitForPendingFinalizers();
                  
                              this.Dispatcher.BeginInvoke(() =>
                              {
                                  GC.Collect();
                                  GC.WaitForPendingFinalizers();
                              });
                          });
                      });
                  }
                  

                  听起来很疯狂,但它确实有效.

                  As crazy as it sounds, it works.

                  在您的情况下,您还有另一个问题.您通过弹出窗口使页面保持活力.让我解释一下:

                  In your case, you have another problem. You are keeping the page alive with your popup. Let me explain:

                  CreatePopups 方法中,您创建弹出窗口并将其添加到起始页的网格中.在弹出窗口中,您启动一​​个计时器以定期调用 UpdateMemoryInfo.计时器由 .NET 运行时保持活动状态,直到它停止.计时器会在您的弹出窗口中保留一个引用,因为您使用实例方法作为事件处理程序.您的弹出窗口通过 Parent 属性保持对网格的引用.网格通过其自己的 Parent 属性保持对页面的引用.所以你只是让你的页面不朽,只要你的计时器在滴答作响.要证明问题存在,只需将 UpdateMemoryInfo 方法设为静态(并删除其中的所有 UI 更新代码).由于事件处理程序现在是静态的,因此计时器不会保存对弹出实例的引用.运行分析器,您会看到页面实例现在已按预期被垃圾收集器回收.

                  In the CreatePopups method, you create the popup and add it to the grid of the starting page. In the popup, you start a timer to call UpdateMemoryInfo at regular interval. The timer is kept alive by the .NET runtime until it's stopped. The timer keeps a reference on your popup because you're using an instance method as event handler. Your popup is keeping a reference to the grid through the Parent property. The grid is keeping a reference to the page through its own Parent property. So you just made your page immortal, for as long as your timer is ticking. To prove that the issue is there, just make the UpdateMemoryInfo method static (and remove all the UI updating code there's inside). Since the event handler is now static, the timer won't hold a reference to instance of popup. Run the profiler, and you'll see that the instance of the page is now reclaimed by the garbage collector as you expect.

                  当然,它假定您的页面已从后台堆栈中删除.通过按返回键或调用 NavigationService.GoBack() 方法,或使用 NavigationService.RemoveBackEntry() 手动删除它们(如果您只使用向前导航)

                  Of course, it supposes that your pages have been removed from the back stack. Either by pressing the back key or calling the NavigationService.GoBack() method, or by manually removing them using NavigationService.RemoveBackEntry() (in case you only use forward navigation)

                  这篇关于删除 Pages windows phone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:标记“当前"的最佳方式菜单中的导航项 下一篇:更改导航 ID 以突出显示当前页面 ASP.NET 的编程解

                  相关文章

                  最新文章

                  <i id='iNG9S'><tr id='iNG9S'><dt id='iNG9S'><q id='iNG9S'><span id='iNG9S'><b id='iNG9S'><form id='iNG9S'><ins id='iNG9S'></ins><ul id='iNG9S'></ul><sub id='iNG9S'></sub></form><legend id='iNG9S'></legend><bdo id='iNG9S'><pre id='iNG9S'><center id='iNG9S'></center></pre></bdo></b><th id='iNG9S'></th></span></q></dt></tr></i><div id='iNG9S'><tfoot id='iNG9S'></tfoot><dl id='iNG9S'><fieldset id='iNG9S'></fieldset></dl></div>
                • <legend id='iNG9S'><style id='iNG9S'><dir id='iNG9S'><q id='iNG9S'></q></dir></style></legend>

                  <small id='iNG9S'></small><noframes id='iNG9S'>

                    <tfoot id='iNG9S'></tfoot>
                      <bdo id='iNG9S'></bdo><ul id='iNG9S'></ul>