Windows Phone内存泄漏90MB-仅两个静态页面 [英] Windows Phone Memory Leak 90MB - only two static pages

查看:68
本文介绍了Windows Phone内存泄漏90MB-仅两个静态页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个(尽可能基本的).XAML页面.

I created two (as basic as you can get) .XAML pages.

StaticPage.xaml

  1. 显示内存使用情况
  2. 链接到MemoryTest.xaml

MemoryTest.xaml

  1. 什么也不做,只显示10个左右的文本块,每个文本块都带有Text ="This is some text".

问题

如果您要做的就是使用超链接在页面之间来回导航,然后使用硬件后退按钮,则内存使用情况看起来不错. 但是如果您一遍又一遍地做下去...两者都是当前的内存使用率,并且总内存使用率会攀升!!!!!一直超过90MB的限制.

If all you do is navigate back and forth between the pages using a hyperlink, and then the hardware backbutton, memory usage looks good. but if you keep doing it over and over... BOTH the current memory usage, and the Total Memory usage climbs !!!!! all the way past the 90MB limit.

在此处查看我的屏幕截图:

View my screenshot here:

旁注:

更快的导航速度或更慢的速度没有什么不同. 没有可用的资源释放,因为没有任何内容,因此无需在代码中做任何事情... 现在,如果您添加更多控件(就像普通应用程序一样,则此过程会更快地增加). 添加更多静态文本块还可以提高达到90MB限制的速度.

Faster navigation or slower does not make a difference. There are no resources to release, no thing to do in code behind becuase there is nothing there... Now if you add more controls (as a normal app would, this process increases faster). Adding more static text blocks also increases the speed the 90MB limit is reached.

这很不好,因为我有一个相册页面,该页面使用的内存没有释放,并且在5分钟或更长时间使用后,它超过了90MB.我需要尝试解决此问题,以便它不会通过市场测试.

This is bad becuase I have a photoalbum page that uses memory that is not getting released and after 5 min or decent usage, it goes over 90MB.. I need to try and get this resolved so it doesnt fail the marketplace test.

这是每个页面后面的代码

Here is the code behind for each Page

StaticPage.xaml

public partial class staticPage : PhoneApplicationPage
{
    public staticPage()
    {
        InitializeComponent();
    }

    private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/TestDir/MemTest.xaml", UriKind.Relative));
        txtMem.Text = String.Format("{0} MB Peak\n{1} MB Current", (DeviceStatus.ApplicationPeakMemoryUsage / 1048576).ToString(), (DeviceStatus.ApplicationCurrentMemoryUsage / 1048576).ToString());
    }
}

MemoryTest.xaml

public partial class MemTest : PhoneApplicationPage
{
    public MemTest()
    {
        InitializeComponent();
    }
}

推荐答案

  • 不要打扰检查模拟器中的内存消耗,这并不精确.使用设备.

    • Don't bother with checking memory consumption in the emulator, it's not precise. Use a device.

      不做过早优化

      编写实际应用时,对其进行概要分析.

      When you written a actual app, profile it.

      调试版本会消耗更多的内存,并且当/如果GC启动,导航后的内存使用量将下降.

      Debug builds consume more memory, and the memory usage will go down after a navigation, when/if GC kicks in.

      请勿使用GC.Collect().只是不要.

      这篇关于Windows Phone内存泄漏90MB-仅两个静态页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆