Search code examples
androiduniversal-image-loader

android universal image loader out of memory


I'm loading about 50 images. In my activity I have this configuration

    DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
            .cacheOnDisk(true).cacheInMemory(true)
            .imageScaleType(ImageScaleType.EXACTLY)
            .resetViewBeforeLoading(true)
            .displayer(new FadeInBitmapDisplayer(300))
            .build();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
        .defaultDisplayImageOptions(defaultOptions)
        .memoryCache(new WeakMemoryCache())
        .diskCacheSize(100 * 1024 * 1024)
        .build();

    ImageLoader.getInstance().init(config);

in binderdata

ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(uri, holder.iv_img);

Some images are loaded, but some are not and I get OutOfMemory error.


Solution

  • Check this tips from Useful Info

    If you often got OutOfMemoryError in your app using Universal Image Loader then:

    1. Disable caching in memory. If OOM is still occurs then it seems your app has a memory leak. Use MemoryAnalyzer to detect it. Otherwise try the following steps (all of them or several):
    2. Reduce thread pool size in configuration (.threadPoolSize(...)). 1 - 5 is recommended.
    3. Use .bitmapConfig(Bitmap.Config.RGB_565) in display options. Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888.
    4. Use .imageScaleType(ImageScaleType.EXACTLY) (Your already use this tips)
    5. Use .diskCacheExtraOptions(480, 320, null) in configuration

    Hope this helps!!