java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android

前端 未结 13 1810
醉话见心
醉话见心 2020-11-22 01:32

I developed an application that uses lots of images on Android.

The app runs once, fills the information on the screen (Layouts, Listviews,

13条回答
  •  盖世英雄少女心
    2020-11-22 02:36

    To avoid this problem you can use native method Bitmap.recycle() before null-ing Bitmap object (or setting another value). Example:

    public final void setMyBitmap(Bitmap bitmap) {
      if (this.myBitmap != null) {
        this.myBitmap.recycle();
      }
      this.myBitmap = bitmap;
    }
    

    And next you can change myBitmap w/o calling System.gc() like:

    setMyBitmap(null);    
    setMyBitmap(anotherBitmap);
    

提交回复
热议问题