post icon

Getting Total Memory on Win7 Mobile Devices

One of the criteria for submitting an application to the Windows 7 Mobile Marketplace is to ensure your applications peak memory usage does not exceed 90 MB of RAM (except on devices with more than 256 MB of RAM). This can easily become the case especially if your application uses a lot of images.

To determine how much memory your application has you will need to access properties contained in DeviceExtendedProperties. DeviceTotalMemory will give you the physical RAM size available in bytes on the device. ApplicationCurrentMemoryUsage will return the current application’s memory usage in bytes. Finally, ApplicationPeakMemoryUsage tells you the application’s peak memory usage in bytes.

 

using Microsoft.Phone.Info;
 
 
long totalMem = (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory");
long currentMem = (long)DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage");
long peakMem = (long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage");
 
 

One quick pointer: If you delete a Image from your application make certain to also set the Image object to null. This will ensure the memory is freed up faster.

Thanks,

–Mike

23. Mar, 2011

1 Comment

Leave a comment
  1. Stanley D. Chatman
    05. Apr, 2011 at 7:48 am #

    I purchased your book Game Programming with SilverLight, however the link to get the source code is dead. How do I obtain the source code for this book.

    Thanks

    DEAD LINK>>>>>
    http://www.courseptr.com/ptr_downloads.cfm