none
Peak Memory Blowing 90MB Limit

    Question

  • I am quite new to WP7 development and was reading some articles around people blowing the 90MB memory threshold that is set for applicatgion submission.

    I have a my MainPage.xaml with 12 buttons with images (4KB each) and each one goes to a new page as follows:

    MainPage.xaml -> Button 1 -> Page1.xaml
    MainPage.xaml -> Button 2 -> Page2.xaml
    MainPage.xaml -> Button 3 -> Page3.xaml
    MainPage.xaml -> Button 4 -> Page4.xaml
    MainPage.xaml -> Button 5 -> Page5.xaml
    MainPage.xaml -> Button 6 -> Page6.xaml
    MainPage.xaml -> Button 7 -> Page7.xaml
    MainPage.xaml -> Button 8 -> Page8.xaml
    MainPage.xaml -> Button 9 -> Page9.xaml
    MainPage.xaml -> Button 10 -> Page10.xaml
    MainPage.xaml -> Button 11 -> Page11.xaml
    MainPage.xaml -> Button 12 -> Page12.xaml

    Each of these sub pages has just plain text in the TextBlock control and nothing else!  I am using a StackPanel within a ScrollViewer to show the text.

    I am sure the PeakMemory usage on the screen everything I navagate between the pages and the memory grows and grows.  What am I doing wrong?  Is there a way to free up memory everytime I navigate back i.e.  If I am on Page1.xaml and navigate back to the MainPage.xaml, can I free memory up by clearing items and text?

    Thanks for all your time.

    Aaron

    Wednesday, October 12, 2011 5:09 PM

Answers

  • Judging by the information here, you did nothing wrong. It's not normal for such a simple application to consume or even leak memory in that way. I have built several applications, mostly for my developer trainings, and even with multiple pages and graphical features they barely exceed 30-40 MB.

    Just to be clear on this: in the first post, you said that the peak memory "grows and grows". In the last post, you're saying that the "PeakMemory counter never drops down". 

    The latter one of course is normal. Like the name suggests, this counter reports the peak memory usage and hence will never drop during the lifetime of the application, but only raise. If however you see this counter to raise and raise when you navigate back and forth between the same pages, then something is apparently stopping your pages from being garbage collected. Without some insights into your code (can you upload the sample application somewhere?) it will be hard to give proper advice.

    Friday, October 14, 2011 5:31 AM
  • Judging by its features I'd say yes, there is a limit :).

    If you want to be on the safe side, you can always send your texts in batches (e.g. use 10 recipients at a time).

    Saturday, November 12, 2011 3:54 AM

All replies

  • Hi Aaron. Unless you have some actual programming mistakes in your application, this free up of memory is done automatically for you. These mistakes can be subtle and not blatantly obvious; for example, if your individual pages directly or indirectly hook events from objects that live longer that themselves. If you forget to unhook these events, these event handlers keep alive the page long after they're visually gone (indefinitely or until the object with the event is freed, to be more precise). This is the most common mistake with pages that show data and navigation - you should closely inspect your code for constellations like that.

    Thursday, October 13, 2011 2:18 AM
  • Thanks for the prompt reply.  I am not data binding anything or creating events of any kind...all that is shown in each page is a TextBlock control with some text in it and that is it.  These pages are just a link from the MainPage.xaml and no images or anything of that nature.

    So when I am navigating between the pages the peak memory increases as I go through the pages.  Is there anyway I can remove the previous page details from memory?  I was reading somewhere that the pages are kept in memory so is that the reason that I am reaching the 90MB limit?

    Thursday, October 13, 2011 4:35 PM
  • The phone only maintains a navigation back stack, which means that all the pages "on the way" to the current one are kept in memory. If however you navigate back (using the hardware back button or the back navigation features) the page you leave is removed from that stack. How are you doing the back navigation?

    Please note that the cleaning may not happen instantly/immediately - just as with other managed environments, this is handled by the garbage collector, and that kicks in periodically and when the runtime thinks it would be a good time to clean up. How do you measure the peak memory consumption of your app? Do you also test on a real device or only in the emulator?

    Thursday, October 13, 2011 5:02 PM
  • Hi once again thanks for the prompt reply. I am trying to move from iPhone development as developing with Silverlight seems so much easier.  I did not have any memory issues with apps that I have helped with or created on the iPhone and just has thrown me off how quickly I can blown the memory on my WP7 app.  I have tried to answer your questions as follows:

    How are you doing the back navigation?
    I am just pressing the back button on the emulator

    How do you measure the peak memory consumption of your app?
    I am using a utility from Coding4Fun with a control called MemoryCounter.  When the app is running the PeakMemory counter never drops down.
    http://coding4fun.codeplex.com/wikipage?title=Memory%20Counter&referringTitle=Documentation

    Do you also test on a real device or only in the emulator?
    At the moment I am testing on the emulator only.  Is there a difference between the two?

    I guess I am trying to weight if it is worth paying the $99 subscription just to be told that a simple app can blow the memory so quickly and my app keeps getting rejected from the marketplace.  Also if the app is really basic, users might not find it worth there time to look at it!

    Also is it acceptable to prompt the user that they are nearing the 90MB threshold and that they might have to restart the application. (Just something I read on a forum!).  I guess this will fail the submission of the app anyway wont it?

    Also I was reading about not using Panorama and Pivot controls as they use to much memory...is this correct?  Is there no way to vitualise them?

    Aaron.

    Friday, October 14, 2011 5:09 AM
  • Judging by the information here, you did nothing wrong. It's not normal for such a simple application to consume or even leak memory in that way. I have built several applications, mostly for my developer trainings, and even with multiple pages and graphical features they barely exceed 30-40 MB.

    Just to be clear on this: in the first post, you said that the peak memory "grows and grows". In the last post, you're saying that the "PeakMemory counter never drops down". 

    The latter one of course is normal. Like the name suggests, this counter reports the peak memory usage and hence will never drop during the lifetime of the application, but only raise. If however you see this counter to raise and raise when you navigate back and forth between the same pages, then something is apparently stopping your pages from being garbage collected. Without some insights into your code (can you upload the sample application somewhere?) it will be hard to give proper advice.

    Friday, October 14, 2011 5:31 AM
  • Sorry for the late reply but I was out of town for work.  I have parked this for now and will get back to it once I understand the basics around Metro styles, image loading and so on. 

    By the way, do you know what the maximum number of recipients is for an sms message?

    Friday, November 11, 2011 2:01 AM
  • Hi again. No problem.

    To be honest I don't know what the upper limit of recipients is, if any.

    Friday, November 11, 2011 3:42 AM
  • The reason I ask is that with the holidays coming, if I want to send "Merry xmax" to say 100 people in my contact list...will I be able to or is there a limit of 10 people per message or something like that?

    I was confussed after reading this article http://www.dailymobilebuzz.com/2011/10/05/advanced-configuration-tool-for-windows-phone-7-mango/ which is for an app that changes the registry setting so wondering what the deal is!

    Friday, November 11, 2011 8:39 PM
  • Judging by its features I'd say yes, there is a limit :).

    If you want to be on the safe side, you can always send your texts in batches (e.g. use 10 recipients at a time).

    Saturday, November 12, 2011 3:54 AM
  • I guess I could loop every 10 recipients and compose a sms task but what even would I wait for to send the other 10 recipients after the first 10 is sent?  Is there a event to wait for?

    Monday, November 14, 2011 5:07 AM
  • I have a need for a company application where we have a file on Skydrive...say the Public folder called 1.txt and the WP7 application needs to be able to load the file in memory and iterated through each row in the file...is this easily done?  Does anyone know of any samples I can look at?

    Thanks.

    A

    Tuesday, December 06, 2011 5:42 AM
  • Hi there. Yes, something like this is possible, you can use the WebClient class, which can download remote files very easily.

    I'm on the road at the moment and don't have time to give you a full example - if that's not enough information to get you started, you should create a new topic so more people can see it. 

    Hope this helps.

    Tuesday, December 06, 2011 6:09 AM
  • Tuesday, December 06, 2011 5:10 PM