zhangke3016 / ViewSpreadTranslationController

View Spread TranslationController for Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OOM 内存溢出

shikechen opened this issue · comments

java.lang.OutOfMemoryError: Failed to allocate a 8294412 byte allocation with 8279288 free bytes and 7MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1071)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1041)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1008)
at helper.AbstractViewHelper.getBitmapWithView(AbstractViewHelper.java:124)
at helper.BaseViewHelper.backActivity(BaseViewHelper.java:299)
at helper.BaseViewHelper.backActivity(BaseViewHelper.java:333)

问题出现的操作:
连续操作几次进入页面再退出时出现。

问题相关代码:
AbstractViewHelper.class
protected Bitmap getBitmapWithView(View v) {
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); // 引起OOM的代码
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
canvas.setBitmap(null);
return bitmap;
}

BaseViewHelper.class
public void backActivity(Activity mActivity, int resultCode, Intent mIntent) {
//省略部分代码
inflate.setBackgroundDrawable(new BitmapDrawable(getBitmapWithView(viewGroup)));
//省略部分代码
}