OutofMemoryError: bitmap size exceeds VM budget (Android)

后端 未结 9 758
甜味超标
甜味超标 2020-11-27 18:48

Getting an Exception in the BitmapFactory. Not sure what is the issue. (Well I can guess the issue, but not sure why its happening)

ERROR/AndroidRuntime(7906): jav         


        
9条回答
  •  萌比男神i
    2020-11-27 19:15

    Make sure to guard your bitmap creation from out of memory errors! With most platforms, android doesn't have much memory to play with and it runs out quickly with bitmaps. Also, make sure to manually recycle your bitmaps as much as possible, I've noticed that the garbage collection can be rather slow.

    try{            
      Bitmap myFragileBitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
    }
    catch(IllegalArgumentException e){
      Log.e(TAG,"Illegal argument exception.");
    }
    catch(OutOfMemoryError e){
      Log.e(TAG,"Out of memory error :(");
    }
    

提交回复
热议问题