Summary of "Javase" Java issues

Source: Internet
Author: User

OutOfMemoryError exception when using Bufferedinputstream

OutOfMemoryError exception when using Bufferedinputstream.

In order for InputStream to be read repeatedly, we will decorate a InputStream instance with Bufferedinputstream.

New Bufferedinputstream (IS); Bis.mark (integer.max_value); // While bis.read (...) Bis.reset

It's actually bufferedinputstream to save the data after Mark and restore it when reset is called, so when there's too much inputstream data, there's a problem, especially when I do Android development on my phone, and when the data is over 13K, It is possible that there is not enough memory to throw down the following exception:

 while executing doinbackground () ...... caused by:java.lang.OutOfMemoryError at    java.io.BufferedInputStream.fillbuf (Bufferedinputstream.java: 156) at    java.io.BufferedInputStream.read (Bufferedinputstream.java:309)    at Java.io.InputStream.read (Inputstream.java:163) at    ...

Therefore, the Mark method requires that the maximum number of bytes to be recorded should not be set as Integer.max_value.

Summary of "Javase" Java issues

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.