Calculating Available Memory

,

Windows Phone 8 device manufacturers are obligated to produce phones that have at least 512MB of RAM.


Note

Although many phones have more than 512MB of RAM, be mindful of the minimum specification and aim to support the lowest common denominator. Do not assume your app will be running on a device with more than 512MB of RAM. Regardless of how much memory the device has, your app’s memory is capped at either 150MB for lower memory phones or 300MB for higher memory phones. The ID_FUNCCAP_EXTEND_MEM capability can be added to your WMAppManifest.xml file to grant more memory to your app. See http://bit.ly/13o7Pmu for details.


To determine how much memory your app has to work with, use the DeviceStatus.ApplicationMemoryUsageLimit.

For example, if a particular task is estimated at costing an additional 10MB of memory, determining whether the task will exceed the memory usage limit can be calculated as follows:

long requiredBytesEstimate = 10 * 1048576; /* 1048576 bytes equals 1 megabyte. */
if (DeviceStatus.ApplicationMemoryUsageLimit
        >= DeviceStatus.ApplicationCurrentMemoryUsage + requiredBytesEstimate)
{
    /* Perform expensive task. */
}


Note

If your app attempts to allocate more memory than is available on the device, that is, it exceeds the value of DeviceStatus.ApplicationMemoryUsageLimit, the application terminates with an OutOfMemoryException.


In addition to foreground app memory constraints, background tasks are limited to 6MB of memory. Background tasks and their memory usage requirements are discussed in Chapter 32, “Conducting Background Activities with Scheduled Actions.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.127.68