That memory thing I promised you

Today Jeff Wilcox, David Anson, and I did a Channel 9 live session with Dan Fernandez at the PDC on Microsoft campus. You can catch it almost exactly 55 minutes into the stream here (note to self: try to remember what team you work on - it's the Application Platform team, not the Application Development team!)

One thing I mentioned was the LazyListBox, which you can find here, and the other ListBox virtualization samples that you can find on the Silverlight Performance blog here.

Anyway, I foolishly promised to publish something on my blog, so here it is. It's a simple class called MemoryDiagnosticsHelper that shows a counter similar to the built-in frame-rate counter that can be used to show how much memory you are using. It will also Assert if you go over the marketplace limit of 90MB, which is nice. It also ensures that the calls to DeviceExtendedProperties are only made in DEBUG mode so that you won't get a scary disclosure in marketplace for "identifying the device."

Anyway, the code is attached along with a very silly sample app. All you really need is the MemoryDiagnosticsHelper.cs file though, which you can pull into your existing apps and add a line like this in App.xaml.cs right under the call to EnableFrameRateCounter

MemoryDiagnosticsHelper.Start(TimeSpan.FromMilliseconds(500), true);

Comments (2)

  1. Runs for 2.5 hrs says:

    at 500 ms and do GC

    MemoryDiagnostics.MemoryDiagnosticsHelper.Start(TimeSpan.FromMilliseconds(500), doGarbageCollectOnTimer);


    return (long)DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage");

    and the peak one fail with an out of range arg after 2.5 hours continuous running.  I've since changed 500 to 2000, and for the heck of it not forcing GC.  Time will tell if the 2.5 is related to the call interval, or the system itself.

  2. Thanks for the feedback. We are tracking this bug internally — don't have any other status right now.

Skip to main content