Question

I have a problem using the Universal Image Loader Library. Unfortunately, the Library causes huge memory usage of my application.

I have a ScrollView (there are tons of reasons why I am using a ScrollView instead of a ListView, most of them have to do with custom insertion and item selection animations) holding about 20 custom Views. Each of those custom views consists of some TextViews as well as an ImageView.

And now here is the thing:

The Images dispalyed in the ImageViews are downloaded from the Internet and all have around 100-150kb (dimension 640 x 320) each. If I download the Images using the UniversalImageLoader my app crashes with an OutOfMemoryException because it uses around 80Mb of memory.

If I do not download the Images, and just put in a Hard-Coded Image with the size of 1200kb (dimension 1920 x 1080) per custom view, my app only consumes around 40Mb of memory.

What am I doing wrong using the UniversalImageLoader when downloading ten times smaller Images causes my app to use up twice as much memory?

I disabled all caching mechanisms but the problem still persists.

Here is my UniversalImageLoader setup:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(c)
        .build();

ImageLoader.getInstance().init(config);

DisplayImageOptions options = new DisplayImageOptions.Builder()
        .showStubImage(R.drawable.loading)
        .showImageForEmptyUri(R.drawable.loading)
        .showImageOnFail(R.drawable.loading)
        .cacheInMemory(false)
        .cacheOnDisc(false)
        .imageScaleType(ImageScaleType.IN_SAMPLE_INT) // default
        .build();

And in code, I call it like this:

ImageLoader im = ImageLoader.getInstance();
im.displayImage("myurl", myimageview, options);

What am I doing wrong? Why is the UniversalImageLoader using up so much memory?

Was it helpful?

Solution

For all the other people out there having the same issues:

I managed to minimize my Memory usage and get rid of the OutOfMemoryException by following these guidelines:

https://github.com/nostra13/Android-Universal-Image-Loader#useful-info

The most important part for me was to reduce the ThreadPoolSize down to 2. I could not feel any performance changes after setting it down.

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(c)
.threadPoolSize(2) 
.build();

DisplayImageOptions options = new DisplayImageOptions.Builder()

// other options

.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY)

// other options
.build();

This reduced my applications total memory consumption by about 35%.

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