Over a million developers have joined DZone.

Detecting and simulating low memory devices in Windows Phone 7 applications

· Mobile Zone

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
        if (Microsoft.Devices.Environment.DeviceType
            == Microsoft.Devices.DeviceType.Emulator)
            return EmulatorIsLowMemory;
            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/


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}