WP7 support guru Reed Robison shared this little gem, I thought I’d pass it on…
You can monitor memory pretty easily during debug…
You can setup a timer in your app.xaml like this:
System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(1000d);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
Which can dump constant memory info using a handler like this:
void timer_Tick(object sender, EventArgs e)
{ //GC.GetTotalMemory(true);
long deviceTotalMemory = (long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceTotalMemory"); long applicationCurrentMemoryUsage = (long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage"); long applicationPeakMemoryUsage = (long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage");
System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString());
System.Diagnostics.Debug.WriteLine("Device Total : " + deviceTotalMemory.ToString()); System.Diagnostics.Debug.WriteLine("App Current : " + applicationCurrentMemoryUsage.ToString()); System.Diagnostics.Debug.WriteLine("App Peak : " + applicationPeakMemoryUsage.ToString()); }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Remember that your app needs to run within a 90mb memory usage limit to pass certification. If you are blowing 90mb the runtime will shut you down when you run on a device. Unfortunately, the emulator (being an x86 compile) doesn’t. So worth monitoring your code just to make sure.