Clamp目标GC堆从55.234MB到48.000MB是什么意思?

时间:2012-12-15 05:51:39

标签: java android garbage-collection heap

我在ma listview之一中使用ImageLoader来显示来自URL的图像。滚动列表时,应用程序没有响应。我检查了logcat并得到了这个日志报告http://pastebin.com/Zfsk7r9X。在此日志中," Clamp目标GC堆从55.234MB到48.00MB"显示。如何避免此内存问题。我在ImageLoader类中完成了System.GC()。 我使用的decodeFile()如下所示

// decodes image and scales it to reduce memory consumption
private Bitmap decodeFile(File f) {
    try {

        // decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f), null, o);

        // Find the correct scale value. It should be the power of 2.
        final int REQUIRED_SIZE = 70;
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < REQUIRED_SIZE
                    || height_tmp / 2 < REQUIRED_SIZE)
                break;
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        // decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    } catch (FileNotFoundException e) {
    }
    return null;
}

1 个答案:

答案 0 :(得分:3)

虚拟机在绝望时记录消息“Clamp target GC heap”,堆分配失败,并在尝试后将堆返回到先前的理想限制。来自HeapSource.cpp中的setIdealFootprint文档:

/*
 * Sets the maximum number of bytes that the heap source is allowed
 * to allocate from the system.  Clamps to the appropriate maximum
 * value.
 */