Freigeben über


Developing apps for lower-memory phones for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

 

For the widest distribution of your app, determine how much memory your app uses, and then adapt your app to perform well on devices with lower memory.

  • For Windows Phone 8, this means phones with 512 MB of memory.

  • For Windows Phone OS 7.1, this means phones with 256 MB of memory.

With the Windows Phone SDK 8.0, you can test your app on a 256-MB or 512-MB version of Windows Phone Emulator. With Windows Phone SDK 7.1.1 Update and later versions of the tools, you can detect in your code whether your app is running on a lower-memory device, and then disable some features of your app, if necessary, to target the largest possible market for your app. Finally, if your app won’t function properly on a lower-memory device, you can opt out of this phone category in the Windows Phone Store by making the appropriate changes to your app manifest file.

This topic describes how to check the memory of the phone. It also describes features in Windows Phone OS 7.1 that aren’t supported or that have limited support on lower-memory devices.

This topic contains the following sections.

 

Checking the app memory limits of the device

With Windows Phone SDK 8.0 or Windows Phone SDK 7.1.1 Update, you can check the memory working set limit of the device hosting your app and Then you can disable some features of your app if you know they aren’t supported or are memory-intensive. To check the memory working set limit, you call the GetValue(String) methodand pass ApplicationWorkingSetLimit for the propertyName parameter. The following code shows how to do this.

// Place call in a try block in case the user
// is not running a version of the Windows Phone OS
// that supports this method call.

try
    {
      long result =  
        (long)DeviceExtendedProperties.GetValue("ApplicationWorkingSetLimit");
    }

catch (ArgumentOutOfRangeException)
    {
      // The device does not support querying for this value. This occurs
      // on Windows Phone OS 7.1 and older phones without OS updates.
    }

The following table shows the value returned by the GetValue(String) method if the phone is a lower-memory device, depending on OS version.

OS Version

App Working Set Limit

Windows Phone 8 default limit

150 MB (157286400)

Windows Phone 8 higher limit

180 MB (188743680)

Windows Phone OS 7.1 

90 MB (94371840)

For more information about memory limits in Windows Phone 8, see App memory limits for Windows Phone 8.

To run within these memory limits, you may have to make adjustments in your app. We recommend that you test the memory use of your app before submitting it to the Store, particularly for apps and games that use a lot of media resources.

Warning

Some calls to GetValue(String) require the device identity capability, ID_CAP_IDENTITY_DEVICE. However, if you use the GetValue(String) method to get the ApplicationWorkingSetLimit parameter, you can opt out of the device identity capability by removing it from the app manifest. For more info, see How to determine app capabilities for Windows Phone 8.

Special feature considerations for low-memory devices

You can use most features offered in Windows Phone 8 and Windows Phone OS 7.1 on lower-memory devices with no performance issues. However, generic background agents are not supported on Windows Phone OS 7.1 lower-memory devices, and a few additional features should be used with care so that you don’t exceed the memory limit of the app.

Reduce graphics and audio memory use

When you develop apps and games to run on lower-memory devices, be careful about how you use graphics in the game or app. Graphics and audio memory often cannot be paged. Too many audio or image resources, textures, and animations can exceed the memory limits of a lower-memory device. This is of particular concern for games built using XNA Framework, which typically use a lot of graphics and audio. If your app or game exceeds the memory level for the device it is running on, an OutofMemoryException will occur and the app will exit unexpectedly.

If the graphics memory use is close to the working set limit of the device, try to tune the performance of your app so that it will work on lower-memory devices. App profiling can help with this task. For more info, see App profiling for Windows Phone 8.

Additional considerations for reducing memory use

Following is a list of additional considerations for developing an app to run on lower-memory devices.

  • Use launchers and choosers, if possible. If you use the WebBrowser control, the Map control, or the camera in your app, be sure to test how much memory your app uses and whether the app runs smoothly on the 256MB Windows Phone Emulator. To reduce the memory load on your app, use these controls with their respective launchers and choosers. For more info about using launchers with Windows Phone, see Launchers for Windows Phone 8 and Choosers for Windows Phone 8.

  • Avoid long lists of data, or if you use them, make sure they are paged. Load the data on demand versus all at once.

  • Avoid complex item templates that have images. If you use them, monitor the memory use of your app.

  • Avoid complex animations on page transitions. This includes the transitions in the Windows Phone Toolkit. If you use transitions, make sure that your app remains responsive, and test the memory use of your app during page transitions.

  • Be aware that if the user changes the device orientation while running an app, the memory used by the app may spike. Test your app with orientation changes and opt out of lower-memory devices if your app regularly exceeds the 90MB memory limit.

For general performance guidelines, such as reducing start time and reporting progress to the user, see App performance considerations for Windows Phone 8.

Avoid generic background agents on Windows Phone OS 7.1 

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

 

The only feature that is not supported on lower-memory devices that target Windows Phone OS 7.1 is generic background agents. The agents are supported on Windows Phone 8, even when the phone is a lower-memory device. The following agents are not supported on Windows Phone OS 7.1, if the phone is a lower-memory device:

  • Resource-intensive tasks

  • Periodic tasks

When you try to add use of these background agents in your app by using the Add(ScheduledAction) method and passing a PeriodicTask or ResourceIntensiveTask, either on a lower-memory device or on the 256MB emulator, an InvalidOperationException exception occurs.

If you use a background agent in your app, and you want your app to run on all types of devices, check the working memory of the device and don’t use the background agent on a lower-memory device. For example, if you use a PeriodicTask control to update a live Tile for your app, disable the live Tile updates for a lower-memory device and provide only a static Tile. For an example that demonstrates how to check this value and how to disable some features of an app, see How to disable features in apps for lower-memory phones for Windows Phone 8.

Testing and debugging apps and games designed for multiple device types

Using the Windows Phone SDK 8.0, you can run your apps on a 256MB Windows Phone Emulator or 512MB emulator. After you install Windows Phone SDK 8.0, you can select from the following options on the standard toolbar.

If you don’t have access to a device, you can use the lower-memory emulators to help determine the responsiveness and performance of your app or game on a lower-memory device.

You can also evaluate your app’s memory usage and tune its performance using tools that are included with Windows Phone SDK.

Opting out of the lower-memory device category in the app manifest

If you test your app and determine that it can’t run within the memory limitations of a lower-memory device, you must indicate this in the manifest file of your app. If you don't, a user with a lower-memory device could download and install your app. This could result in poor ratings for your app from users of lower-memory devices.

To opt out of developing apps for lower-memory devices, add a section to the manifest that specifies that your app requires additional memory. This section of the manifest will not be removed during the Store ingestion process.

To make your app unavailable to lower-memory devices through the app manifest file, do the following steps.

  1. Add a Requirements section to the WMAppManifest.xml file.

    For a Windows Phone 8 app, add the Requirements section immediately following the ScreenResolutions section.

    -or-

    For a Windows Phone OS 7.1 app, add the Requirements section immediately following the Capabilities section.

  2. Add a Requirement element to the Requirements section.

    For a Windows Phone 8 app, specify a Name attribute value of ID_REQ_MEMORY_300 for this Requirement.

    -or-

    For a Windows Phone OS 7.1 app, specify a Name attribute value of ID_REQ_MEMORY_90 for this Requirement.

The following example shows how to do this.

<Requirements>
      <Requirement Name="ID_REQ_MEMORY_300" />
</Requirements>

If you have a Windows Phone OS 7.1 app and you also want to opt out of Windows Phone 8 lower-memory devices, set the requirement to ID_REQ_MEMORY_300. The ID_REQ_MEMORY_300 requirement effectively opts out of both Windows Phone OS 7.1 lower-memory devices and Windows Phone 8 lower-memory devices. If you specify both ID_REQ_MEMORY_90 and ID_REQ_MEMORY_300, the ID_REQ_MEMORY_90 requirement is ignored.

See Also

Other Resources

App performance considerations for Windows Phone 8

Windows Phone Store Test Kit for Windows Phone 8

Windows Phone Application Analysis for Windows Phone 8