android低内存补丁,Android – 从低内存条件恢复

我正在开发一个非常强烈的图像处理应用程序,我在水平FragmentStatePagerAdapter中有多个ListFragments.我积极地采用几乎每一个窍门和建议,我能够在这里和其他地方找到.我下载位图并将其保存到SD和软参考存储器缓存.

然而,当我在某些时候使用该应用程序,我开始在LogCat中看到消息,就像下面一样

11-05 15:57:43.951: I/dalvikvm-heap(5449): Clamp target GC heap from 32.655MB to 32.000MB

11-05 15:57:43.951: D/dalvikvm(5449): GC_FOR_MALLOC freed 0K,24% free 11512K/14983K,external 17446K/17896K,paused 64ms

11-05 15:57:44.041: D/dalvikvm(5449): GC_EXTERNAL_ALLOC freed <1K,24% free 11511K/14983K,external 17258K/17896K,paused 77ms

如果我继续,上面的消息将变得更加迫切

11-05 16:02:09.590: D/dalvikvm(5449): GC_FOR_MALLOC freed 0K,23% free 11872K/15239K,external 17497K/17896K,paused 71ms

11-05 16:02:09.700: D/dalvikvm(5449): GC_EXTERNAL_ALLOC freed <1K,paused 84ms

11-05 16:02:09.720: E/dalvikvm-heap(5449): 192816-byte external allocation too large for this process.

11-05 16:02:09.800: I/dalvikvm-heap(5449): Clamp target GC heap from 33.057MB to 32.000MB

11-05 16:02:09.800: D/dalvikvm(5449): GC_FOR_MALLOC freed 0K,paused 68ms

11-05 16:02:09.800: E/GraphicsJNI(5449): VM won't let us allocate 192816 bytes

并且不可避免的应用程序将与OutOfMemoryException崩溃

症状是经典的内存泄漏.在我的Fragment#onDestroy方法中,我取消所有待处理的任务,取消绑定和取消视图,并调用Bitmap#recycle.

有趣的是,我在LogCat中看到GC调用,但是即使我暂停长时间,内存也不会被回收.

我的直觉是,从SD中连续重新读取图像,导致退化和不可避免的死亡

这里的实用程序清理方法我正在试图摆脱drawables(有更多的我说要取消挂起/运行任务和空ListView适配器)

public static void unbindDrawables(View view,final boolean agressive) {

if (view instanceof ViewGroup) {

for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {

unbindDrawables(((ViewGroup) view).getChildAt(i),agressive);

}

if (!AdapterView.class.isInstance(view)) {

((ViewGroup) view).removeAllViews();

}

} else {

Drawable bmp = view.getBackground();

if (bmp == null && ImageView.class.isInstance(view)) bmp = ((ImageView) view).getDrawable();

if (bmp != null) {

bmp.setCallback(null);

if (agressive && (TaggedDrawable.class.isInstance(bmp))) {

Bitmap bm = ((BitmapDrawable) bmp).getBitmap();

if (bm != null) {

if (DEBUG) Log.i(TAG,"Forcing bitmap recycle for " + bmp);

bm.recycle();

bm = null;

view.destroyDrawingCache();

view = null;

}

}

}

}

}

不用说,我在这一点上受到严重的打扰,非常感谢任何建议

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值