Android Learning--reference images cause memory overflow java.lang.OutOfMemoryError

Source: Internet
Author: User

The problem with today is that calling Bitmapfactory.decodefile (name) from an input stream gets a bitmap error. The first call is no problem, the second call will report the above memory overflow problem. And some mobile phone reported some mobile phone does not report. Study for a half-day finally solved. First, the following reason is analyzed, it should be that the image occupies more memory than the system virtual machine can allocate the maximum limit. Different phones may be assigned the same maximum value. Later the solution was to set the bitmapfactory.options.


bitmapfactory.options option = new Bitmapfactory.options ();        Option.insamplesize = 4;            try {Bitmap bmp = Bitmapfactory.decodefile (path,option);        Holder.icon.setImageBitmap (BMP); } catch (OutOfMemoryError err) {}

Some say to add bitmapoptions.injustdecodebounds = True, but I add the resulting bitmap is null. You can do it after you remove it. Follow the above method to solve the problem. It is better to recycle bitmap when not in use:

if (bitmap! = null &&!bitmap.isrecycled ())

Bitmap.recycle ();


Android Learning--reference images cause memory overflow java.lang.OutOfMemoryError

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.