Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Detecting and simulating low memory devices in Windows Phone 7 applications

DZone's Guide to

Detecting and simulating low memory devices in Windows Phone 7 applications

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

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/


Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}