diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 3ad34edc7..804b5a6fa 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -77,6 +77,7 @@ import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.utils.LoadDian9TuUtil; import com.yunbao.live.utils.UnzipFromAssets; import com.yunbao.live.views.AbsLiveViewHolder; import com.yunbao.live.views.LiveAddImpressViewHolder; @@ -1474,6 +1475,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL protected void release() { EventBus.getDefault().unregister(this); LiveHttpUtil.cancel(LiveHttpConsts.SEND_DANMU); + LoadDian9TuUtil.clearBitmap(); if (mKeyBoardHeightUtil != null) { mKeyBoardHeightUtil.release(); } diff --git a/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java b/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java index d2e3275b3..35574c537 100644 --- a/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java +++ b/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java @@ -15,11 +15,15 @@ import android.view.View; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; +import com.yunbao.live.activity.LiveActivity; import java.io.File; import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.List; public class LoadDian9TuUtil { + private static final List BITMAP_CACHE=new ArrayList<>();//.9图Bitmap缓存 public static void loadDian9Tu(Context context, View imageView, String imgUrl, int position) { if (context == null) { @@ -39,9 +43,11 @@ public class LoadDian9TuUtil { @Override public void onResourceReady(@NonNull File resource, @Nullable Transition transition) { try { - FileInputStream is = new FileInputStream(resource); - setNinePathImage(context, imageView, BitmapFactory.decodeStream(is), position); - + FileInputStream is=new FileInputStream(resource); + Bitmap bitmap=BitmapFactory.decodeStream(is); + BITMAP_CACHE.add(bitmap); + setNinePathImage(context, imageView, bitmap, position); + is.close(); } catch (Exception e) { e.printStackTrace(); } @@ -63,4 +69,16 @@ public class LoadDian9TuUtil { imageView.setBackground(patchy); } } + + /** + * @see LiveActivity#onDestroy() 结束时,释放掉.9图缓存 + */ + public static void clearBitmap(){ + for (Bitmap bitmap : BITMAP_CACHE) { + if(bitmap!=null) { + bitmap.recycle(); + } + } + BITMAP_CACHE.clear(); + } }