Windows Phone 7 Navigation Memory Usage Just Got Scary

by Nick 10. February 2011 19:36

In my previous post I showed a couple of graphs of memory usage with some basic pages within a Windows Phone 7 application. Now I’ve started adding some content to the pages. First up I’ve added a single button to the second page:

<phone:PhoneApplicationPage x:Class="OptimisePerformance.SecondPage"
                            xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone">
    <Button />
</phone:PhoneApplicationPage>

Let’s see what happens….

image

- 2 Pages w Button (iterative): Iterative navigation between the MainPage and the second page every approx 6 seconds.

- 2 Pages w Button (iterative) (GC): Same again but this time GC.Collect is called before retrieving memory usage information

Now this is somewhat scary. Notice that when GC.Collect is called the memory usage is pretty much as you would expect. As you navigate to a page, memory usage goes up; As you go back to the MainPage the memory is reduced; Overall no memory usage increate. Unfortunately this is not the case if you don’t call GC.Collect. It appears that memory usage (both max and current) progressively increases over time. It does kind of hit a ceiling but it’s significantly higher than even the memory usage when the second page is displayed.

This backs up my previous post when I hinted that you may want to selectively call GC.Collect to free up memory.

**Note: I’m not sure what the sudden drop in the current memory usage for when GC.Collect wasn’t being called. This is probably just an anomaly of the way the data is being recorded.

Tags:

Comments (3) -

2/11/2011 4:47:10 AM #

Jon Skeet

Well, that shows that the memory usage is lower if you call GC.Collect(). That doesn't show that it's actually a problem not to call GC.Collect()... because I'd expect the GC to kick in *when the system thinks it needs to*.

If you can show an application going over the 90MB limit due to not calling GC.Collect(), *that* would be scary.

Jon Skeet United Kingdom |

2/11/2011 5:03:46 AM #

nick

Actually I doubt that would be too diffcult - just use a moderately complex panorama control on the MainPage followed by a pivot on the second page. That seems to blow out memory considerably and without a call to GC.Collect your application will go over the 90Mb threshold. That said, don't forget that all devices in market all have more than the minimum 256Mb of RAM

nick Australia |

2/17/2011 7:51:50 AM #

Pansoft

To my experience the main problem with memory usage comes from the heavy usage of images. An empty panorama control with a 1024x768 image and nothing more can easily make you start at 50MB standard usage. From there you can just climp up.
Check the movies linked in our blog to showcase Slave2Beauty (dont get caught too much by the pictures ;)) to see what king of image-juggling we had to do to do not hit the ceiling...

regards

Pansoft Italy |

Pingbacks and trackbacks (1)+

Powered by BlogEngine.NET 2.0.0.36

Automotive Theme by Car Leasing Experts

 

Page List