Windows Phone panorama RAM usage (i.e. crazy high)

Tweet about this on TwitterShare on FacebookShare on RedditShare on Google+Email this to someonePin on Pinterest

I’m nearing the end of a Windows Phone 7.1 app that I’m writing. It’s a TV-related app and as such has a lot of images – so keeping RAM usage down is really important.

Visual Studio has a pretty awesome performance profiler for WP apps, and I suggest you use it frequently. So while checking my app’s memory usage I noticed something very worrying. Around startup the usage was ramping up to over 250MB- that’s massive for a phone app, and is waaaay over the 90MB limit to pass certification.

Here is the usage graph:


After a process of elimination I eventually narrowed it down to the background of the panorama. Namely, the fact that it was set to a web URL (not a local one).

I thought it must just be that I’ve done something odd elsewhere so I created a default 7.1 panorama app, and tried the same thing. While the usage was a lot less, the behavior was pretty much exactly the same:


So next, I tried setting the background in code. It produced the same result as setting it in XAML. So I tried immediately forcing a garbage collect when it was done:


But still, that was stupidly high. Especially considering the image is actually really small (about 20KB – although remember that is compressed).

So working on the knowledge that this massive memory usage doesn’t happen when the background is set to a local resource, the obvious solution is to just save the image to IsolatedStorage! Low and behold, it works Smile


So here is some code I threw together that does the above. You give it a URL and it first checks if the image already exists in IsolatedStorage, if so, it reads it and then sets the background to that, if not then it downloads it first. Also, in my scenario the image will change about once per day and will never go back to a previous one, so I delete the old image each time.


I’m not really sure why the usage is so damn high when you let SL download it itself, but either way, the code above solved it for me.


Still, even with this (or setting it to a local image)…



I did some other tests while speaking to @lancewmccarthy and @archiecoder on the Twitters about this. Incase I had broken something while playing with my test solution, I made yet another solution (once again using the default 7.1 Panorama template).
Something to note:

-To be absolutely sure of the results, between every test (the ones above too) I uninstalled the app and redeployed.
-I’m using the properties pane to set the source, so that SL will make the XAML what it suggests.
-I’m using my 920 – however the same happened on a Samsung Focus Flash

Archie suggested that it might be that SL is having the resize the image (original image was 1,024px × 498px) to fill the screen and that might have a hit. So I resized it (to fit the height – 1,644px × 800px) and uploaded it somewhere. The results were even scarier this time:


Then I added that same image to the solution (Content) and set that as the source:


Next up, just for kicks, I uploaded the default background from the template (the hideously ugly blue one: and set that as the source:


I am desperately hoping that both of my phones are magical RAM black holes – because surely this can’t have gone through any sort of testing? Even if in the docs MS have said never to use a web URL as source (I can’t find anything on the matter), VS has no problem allowing it, and is a very easy pitfall.

Tweet about this on TwitterShare on FacebookShare on RedditShare on Google+Email this to someonePin on Pinterest