Windows Phone Memory Leak 90MB - only two static p

2019-06-25 06:11发布

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

StaticPage.xaml

  1. Shows memory usage
  2. Links to MemoryTest.xaml

MemoryTest.xaml

  1. Does nothing but displays 10 or so Text Blocks each wiht Text="This is some text".

PROBLEM

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:
enter image description here

SideNotes:

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.

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();
    }
}

1条回答
手持菜刀,她持情操
2楼-- · 2019-06-25 07:00
  • Don't bother with checking memory consumption in the emulator, it's not precise. Use a device.

  • Don't do premature optimization

  • When you written a actual app, profile it.

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

  • Don't use GC.Collect(). Just don't.

查看更多
登录 后发表回答