[Android interface]setimageresource and Setimagebitmap

Source: Internet
Author: User

The first type of setimageresource is to draw the object drawable from the resource drawable through the resource ID. This method automatically applies a resolution. Suitable for infrequently set picture picture resources not too big. But

For large pictures, or you need to constantly repeat the settings of the image call this method generated by the drawable will generate a bitmap object because bitmap is generated by Bitmapfactory have a part to call C library so need to open up a part

Native local memory space and a portion of the JVM's memory space. and native local memory space is a C-opened JVM's GC garbage collector is not recycled this part of the space, this time if you frequently call Setimageresource and do not manually adjust

Recycle native's memory space is difficult to release. The JVM's memory is not recycled in a timely manner, so it is quite easy to cause memory overflow.


and Setimagebitmap when you need to set up large pictures frequently by bitmapfactory generate bitmap then set and then manually drop the previous bitmap before each set to the recoverable state so that a large extent can prevent memory leaks overflow

So look at your needs your pictures are not frequently set and will not be too large to use the first if the need to constantly repeat the update settings that the best use of the second and remember to manually recycle and then set if useful to the picture cache, do not include large images in the cache

In the picture of the cache module is best to store only small and frequently used images to save memory and time overhead the large map requires manual recycling to ensure that the low-end point of the machine will not oom

[Android interface]setimageresource and Setimagebitmap

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.