Android memory overflow causes and Corresponding Solutions

Source: Internet
Author: User
Tags try catch

The new version is released. The next day, we will see the feedback. One of the many errors is java. lang. outOfMemoryError: bitmap size exceeds VM budget. It is impossible for cainiao to modify this issue. I will look at how the boss can modify it. Memory overflow is generally caused by too many images. He is thinking about image loading and cleaning. He has never thought of similar problems in the pad version, why does the mobile phone version appear. After reading the pad version code, I suddenly thought that after the page Jump, I forgot to recycle the image cache and add it to the code.
@ Override
Public void onDestroy (){
Super. onDestroy ();
If (checkImage! = Null ){
CheckImage. clearBitmap ();
The problem is solved. The checkImage variable is used to process image loading. Our client needs to use a lot of images. The processing method of images in the program is the first step. First, check whether there are loaded images in the memory, and then check the local (SD card) if there is no picture in the second step) is there any stored image in, and finally the request is sent to the server. The system will process the memory, but because the image is loaded more frequently, if you do not clean it manually, it is also prone to memory overflow.
ClearBitmap function:
Public void <span style = "font-size: 18px;"> clear </span> Bitmap (){
If (hm! = Null ){
Try {
Iterator <Map. Entry <String, Bitmap> it = hm. entrySet (). iterator ();
While (it. hasNext ()){
Map. Entry <String, Bitmap> entry = it. next ();
Bitmap bm = entry. getValue ();
Bm. recycle ();
Bm = null;
Hm. clear ();
} Catch (Exception e ){
Another problem is the NULL pointer error Caused by: java. lang. nullPointerException: The frequency of this problem is also relatively large, but this problem is not self-resolved and is an occasional error. For such errors, all we need to do is ensure that the client does not crash, so find the row corresponding to the error, check the approximate location of the NULL pointer, and then use try catch to capture it, no other processing is required. This error does not affect ordering and viewing important information on the client.

Author: walker02

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: 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.