Android memory analysis, load local image memory optimization

Source: Internet
Author: User

From the Web to learn the mat plug-in to see memory usage, the analysis found that the application of the hand on the local image side of the memory loss is very large, after checking the relevant data found that if the use of Setimagebitmap, setimageresource these to load local resources, will produce a larger loss. Because these methods finish decode, they end up with the Java layer's createbitmap, which consumes more memory. Therefore, instead of using the Bitmapfactory.decodestream method first to create a bitmap, and then set it to ImageView Source,decodestream the biggest secret is its direct call jni>> Nativedecodeasset () to complete the decode, eliminating the need to use the Java layer CreateBitmap, thus saving the Java layer of space. If the Config parameter is added at the time of reading, it can more effectively reduce the loaded memory, thus more effectively prevent throwing memory exception. (http://www.cnblogs.com/sunzn/archive/2013/03/14/2960293.html)

The following optimization scenarios are then taken according to the actual scenario:

1. Cut the picture properly and reduce the quality. (Image size reduced a lot, but memory efficiency is generally, heap occupancy from 3M reduced to 2m)

2. Because the use of the scene is this picture is a large background map, do not know Setimageresource will produce a relatively large consumption of time to come up with the picture to the Web, the use of loading images of the third-party library to load the method.

3. In finding the data to understand the causes of consumption, the Decodestream approach was adopted, with a significant effect and reduced to dozens of K.

this new false= Bitmap.Config.RGB_565;    true ;   true  = 1=bitmapfactory.decodestream (IS,null, options); Im_bg.setimagebitmap (BTP) ;

Before optimization

After optimization

Android memory analysis, load local image memory optimization

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.