6

I'm using ImageLoader in one of ma listview to display images from URL. While scrolling the list, app didn't response. I checked logcat and got this log report http://pastebin.com/Zfsk7r9X. In this log, "Clamp target GC heap from 55.234MB to 48.00MB" is shown. How can I avoid this memory issue. I've done System.GC() in ImageLoader class. decodeFile() which i used is shown below

// 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;
}
trincot
  • 317,000
  • 35
  • 244
  • 286
ASP
  • 81
  • 1
  • 1
  • 4
  • I suspect that understanding what the "Clamp target GC heap" message means won't help solve your problem. – Stephen C Dec 15 '12 at 06:06
  • This may be a duplicate: http://stackoverflow.com/questions/11820266/android-bitmapfactory-decodestream-out-of-memory-with-a-400kb-file-with-2mb-f. – yakshaver Dec 15 '12 at 06:16
  • @StephenC Thnx for reply. Then how will i solve this? App force closed in sometimes(like bluemoon) – ASP Dec 15 '12 at 06:27
  • @yakshaver Thnx for reply. I saw and tried it. But issues remain. :( – ASP Dec 15 '12 at 06:29
  • 1
    You solve the problem by following the advice in http://stackoverflow.com/questions/11820266/android-bitmapfactory-decodestream-out-of-memory-with-a-400kb-file-with-2mb-f ... or getting more memory. Basically, your app is trying to use too much memory – Stephen C Dec 15 '12 at 10:33

1 Answers1

5

The message "Clamp target GC heap" is by logged by the VM when it gets desperate, a heap allocation fails, and the heap is returned to a previous ideal limit after the attempt. From documentation of setIdealFootprint in HeapSource.cpp:

/*
 * Sets the maximum number of bytes that the heap source is allowed
 * to allocate from the system.  Clamps to the appropriate maximum
 * value.
 */
yakshaver
  • 2,472
  • 1
  • 18
  • 21