Question

I was wondering is the universal-image-loader (Found Here) is supporting versions prior to honeycomb. Because versions prior to honeycomb have a separate native heap stack the memory used by the bitmaps does not count towards the VM heap.

I'm developing an image intensive app that is using this lib and I did successfully use it on android ICS. Now I'm trying to lower the API requirements and I'm having some trouble staying away from the Out of Memory exceptions which make my app crash.

Was it helpful?

Solution

Universal Image Loader supports 1.5+ Android versions. UIL tries to prevent OOM by using of weak references and own logic for caching and reference cleaning. For effective memory management in Android versions prior to 3.0 we need use Bitmap.recycle() to clear native memory. But UIL can't do it itself because it can't know when Bitmap is not visible and not referenced by anyone.

User should do recycling yourself, when he know that he can do it.

Also there are some UIL configuration tuning is possible for preventing OOM.

P.S.: How to define if Bitmap is in UIL memory-cache:

Bitmap bmp = ...;
boolean isBitmapInCache = false;
MemoryCacheAware<String, Bitmap> memoryCache = ImageLoader.getInstance().getMemoryCache();
for (String key : memoryCache.keys()) {
    if (bmp == memoryCache.get(key)) {
        isBitmapInCache = true;
        break;
    }
}

if (!isBitmapInCache) {
    // You can recycle bitmap
}

OTHER TIPS

It should work, it computes bitmap size as:

 bitmap.getRowBytes() * bitmap.getHeight();

Which gives correct bitmap size regardless of it being on java or native heap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top