Windows Phone 7 90M memory limit issues and design principles

Source: Internet
Author: User

One. in WP7, the program uses no more than 90M of memory, or it exits automatically.

Two. If a page is not freed, all of the control resources it contains are not garbage collected.

Manipulating an image resource in WP7 is very memory-consuming, and the image control we define in a XAML file, because it belongs to a static resource.

So you can't image.source them in the background CS code = NULL operation.

Unless you put the definition of the image control in the CS code,

This way you perform image.source = null operation or

Remove the image control from the LayoutRoot: LayoutRoot.Children.Remove (image), then the image is garbage collected.

Therefore, for image controls defined in a XAML file, the only time to release the memory occupied by these images is to leave the page.

So, one important principle: Try not to use a page that contains a large number of image controls as your mainpage, because the page will not be released until the end of the program (exit).

So the advice is:

1. If the program has a main interface, try not to put too many image controls on the main interface.

Or, do not use a page with a large number of images as the main page.

2. Whenever possible, make a page that needs to be animated and contain a large number of images, and leave the page as soon as it finishes or runs out.

A 3.Panorama background can consume a lot of memory if it is set to image images. Generally 24M or so, and whether it is JPG or PNG, with the image size and complexity also does not matter.

The only way to reduce memory consumption is to say that the height of the panorama (height) is reduced, for example by half, then the memory consumption is reduced generally, because it only draws half of the interface.

You might think of setting the panorama background to a gradient, which I've tried, and it consumes 17M of memory.

If set to monochrome (solid color brush), it consumes about 2-3m.

The only thing that doesn't consume memory is: no background. So, before choosing Panorama, take a good look at how much memory your program is currently consuming.

The rest of the memory is not enough you load a panorama big stomach king.

4. I heard that pivot is also a love and hate thing, you add a lot of tab to a pivot, and the image is too long, it may also hang.

In addition, a piece of code is included to let you know in WP7, how to let you know when each page is released?

#if(DEBUG)

/// <summary>

/// Add a finalizer to check for memory leaks

/// </summary>

~YourPage()

{

System.Diagnostics.Debug.WriteLine("Finalizing "+ this.GetType().FullName);

}

#endif

You can add this code to each of your page and remember to modify the destructor name.

Then when the page is refactored, it will be seen in the output console.

This article from Sphinx007 's blog, the original address: http://www.cnblogs.com/SphinX/archive/2012/03/12/2391331.html

Windows Phone 7 90M memory limit issues and design principles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.