Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!
Windows Phone Zone is brought to you in partnership with:

I have worked for several companies as a senior software developer and lead developer. I bave enterprise level programming experience on Web, Silverlight, and Windows Phone 7. I am a MVP in Device Application Development since 2011. Jevgeni is a DZone MVB and is not an employee of DZone and has posted 40 posts at DZone. You can read more from them at their website. View Full User Profile

Detecting and simulating low memory devices in Windows Phone 7 applications

12.12.2011
Email
Views: 2367
  • submit to reddit
It's so easy to get up and running with your first Windows Phone app!  Just pick up the FREE toolkit from Microsoft, register at AppHub, and start checking out some fundamental tutorials.

Probably most of you have read Performance and Resource Management part of Windows Phone 7 Application Certification Requirements v1.4 document concerning requirements to memory consumption. In particular, there is a sentence regarding low memory devices (which have only 256 MB of RAM installed): “An application must not exceed 90 MB of RAM usage, except on devices that have more than 256 MB of memory”. In this short post I will describe how to detect such devices.

Basically, we need to detect low memory devices to determine what amount of memory is at our disposal and take advantage of it. For example, we can show high quality images on devices, which have more than 256 MB of memory installed and low quality images (i.e in Panorama control) for other devices.

Detecting and simulating low memory devices

To determine a total amount of available memory you need to use DeviceExtendedProperties class with GetValue method and pass “DeviceTotalMemory” key there. That method will return an amount of memory in bytes. This number should not be greater than 256 Megabytes (268435456 Bytes) for low memory devices. To simulate such device in emulator I will simply use a boolean variable (true – for low memory device, false – for other devices).

private const bool EmulatorIsLowMemory = false;
 
public bool IsLowMemoryDevice
{
    get
    {
        if (Microsoft.Devices.Environment.DeviceType
            == Microsoft.Devices.DeviceType.Emulator)
        {
            return EmulatorIsLowMemory;
        }
        else
        {
            return (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory")
                <= 268435456;
        }
    }
}

Memory Consumption

According to Windows Phone 7 Application Certification Requirements document we should use “ApplicationPeakMemoryUsage” key for DeviceExtendedProperties to query the peak of memory usage. There is a nice tutorial on MSDN of that process. Here is the code I use for this purpose:

long peak = (long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage")

Additional information



Source: http://www.eugenedotnet.com/2011/05/detecting-and-simulating-low-memory-devices-in-windows-phone-7-applications/


Published at DZone with permission of Jevgeni Tšaikin, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

The Windows Phone Microzone, which is supported by Microsoft, is your one-stop-shop for news, tutorials, perspectives, and research on the mobile platform that is making waves in smartphone ecosystem.

Comments

Robert Craft replied on Thu, 2012/01/26 - 6:08am

Worth reading this post as well if you have low memory issues, this wasn’t a good experience! http://rd3d2.wordpress.com/2011/04/23/help-my-certification-testing-has-been-temporarily-suspended/

Spring Framework

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.