I'm using LRu Cache to download and display images from http protocol. My app is one Activity with 5 fragments. Each fragment load a Custom ListView with images and text.
My app always crashes after a while.
This is my LogCat:
11-03 18:00:22.613: E/dalvikvm-heap(1558): Generating hprof for process: com.example.example PID: 1558 11-03 18:00:24.004: E/dalvikvm(1558): can't open /data/misc/app_oom.hprof: Permission denied 11-03 18:00:24.064: E/dalvikvm-heap(1558): hprofDumpHeap failed with result: -1 11-03 18:00:24.064: E/dalvikvm-heap(1558): After hprofDumpHeap for process 11-03 18:00:24.064: E/dalvikvm(1558): Out of memory: Heap Size=196608KB, Allocated=193561KB, Limit=196608KB, Proc Limit=196608KB 11-03 18:00:24.064: E/dalvikvm(1558): Extra info: Footprint=196552KB, Allowed Footprint=196608KB, Trimmed=12KB
And this is my LRU Class:
public class NBitmapCache extends LruCache<String, Bitmap>
implements ImageCache{
public NBitmapCache(int maxSize) {
super(maxSize);
}
public NBitmapCache(Context ctx) {
this(getCacheSize(ctx));
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
// Returns a cache size equal to approximately three screens worth of images.
public static int getCacheSize(Context ctx) {
final DisplayMetrics displayMetrics = ctx.getResources().
getDisplayMetrics();
final int screenWidth = displayMetrics.widthPixels;
final int screenHeight = displayMetrics.heightPixels;
// 4 bytes per pixel
final int screenBytes = screenWidth * screenHeight * 4;
return screenBytes * 3;
}
}
I searched in this forum and Google how to solve this problema, but I don't accomplish solve it. Anyone can help me? The target of my application is from sdk 8.
Thanks in advance.