1

I have an application that needs to display full screen image, i get images from drawable folder and they are like 150-250 kb but it still crashes and gives OutOfMemory error. Not of course very first image, but i load different images everytime user launches application.

As i checked cache folder, i saw images that library cached are about 700-800 kb not as small as mine. So there is something about caching. How can i prevent that happening?

Here is my configuration:

DisplayImageOptions options = new DisplayImageOptions.Builder() .resetViewBeforeLoading(true) .cacheOnDisc(true) .cacheInMemory(true) .displayer(new FadeInBitmapDisplayer(300)) .imageScaleType(ImageScaleType.EXACTLY) .bitmapConfig(Bitmap.Config.RGB_565) .build(); ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this) .defaultDisplayImageOptions(options) .build(); ImageLoader.getInstance().init(configuration); 

And second question: what is default cache limit? Or is there any? Should i specify myself? Because i do not desire to keep all images in cache, please assume that i will also use library to load images from internet not only from drawable.

Edit: I just find out this page which explains a lot, but i see that by default library uses UnlimitedDiscCache and it provides faster caching... Now i have a dilemma about having faster cache (which is really important in my application) or having limited cache size and saving user from clearing cache folder manually... What should it be?

Edit 2: Here is OutOfMemory stackTrace:

E/dalvikvm-heap(17258): Out of memory on a 25600016-byte allocation. I/dalvikvm(17258): "uil-pool-1-thread-2" prio=4 tid=14 RUNNABLE I/dalvikvm(17258): | group="main" sCount=0 dsCount=0 obj=0x428941b0 self=0x59672008 I/dalvikvm(17258): | sysTid=17620 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1572156040 I/dalvikvm(17258): | schedstat=( 104225123 75715335 52 ) utm=10 stm=0 core=0 I/dalvikvm(17258): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) I/dalvikvm(17258): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623) I/dalvikvm(17258): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:476) I/dalvikvm(17258): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781) I/dalvikvm(17258): at android.content.res.Resources.loadDrawable(Resources.java:1963) I/dalvikvm(17258): at android.content.res.Resources.getDrawable(Resources.java:672) I/dalvikvm(17258): at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromDrawable(BaseImageDownloader.java:188) I/dalvikvm(17258): at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:85) I/dalvikvm(17258): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.downloadImage(LoadAndDisplayImageTask.java:319) I/dalvikvm(17258): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryCacheImageOnDisc(LoadAndDisplayImageTask.java:298) I/dalvikvm(17258): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:241) I/dalvikvm(17258): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141) I/dalvikvm(17258): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) I/dalvikvm(17258): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) I/dalvikvm(17258): at java.lang.Thread.run(Thread.java:856) A/libc(17258): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 17620 (uil-pool-1-thre) 

Edit 3:

Problem solved, please see my own answer. But i accepted Delblanco's answer, because it is more efficient.

6
  • Size on disc != size in memory, a bitmap with default configuration takes w*h*4 bytes in memory, for a 2 mpixel image that means 8 Mb memory Commented Jan 10, 2014 at 8:24
  • Could you post the OOM exception stack trace? Commented Jan 10, 2014 at 8:28
  • By 'As i checked cache folder' i meant size on disc... @Magnus Commented Jan 10, 2014 at 8:28
  • 1
    Updated question with stackTrace @Magnus Commented Jan 10, 2014 at 8:34
  • Which folder do you mean by 'i get images from drawable folder'. is it some download folder of yours, or the 'R.drawable.***' Commented Jan 10, 2014 at 9:08

3 Answers 3

4

If possible you should use the native way of showing images from drawable folder. Source

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, but i thought that way i should've handled scaling issues by myself and i was already using this library so decided to go with it. But i didn't know that it is especially declared in library's page to use native way. So i'll give it a shot. Thanks ;)
And that's even better solution than using Universal Image Loader, so i'll accept your answer. Thanks again :)
0

25600016 bytes, is a 25 Mb you're asking to load into memory, or equivalent of a 6 mpixel image with ARGB_8888 Bitmap.Config. It's way to big to load, you need to downsample (see inSampleSize) and read this. In your case you should UIL to downscale the image. I see also that you explicitly set the Bitmap.Config to RGB_565 which means that you actually are dealing with an even larger image, 12 mpixel image?

Comments

0

I've solved the issue. The problem was i had put images into drawable folder before. Images are really big, like 1000*1600px, so i move them into drawable-xxhdpi folder and somehow OutOfMemory error disappears. Any idea why?

2 Comments

See this answer: stackoverflow.com/a/14877627/2246121 the system tried to scale up your "small" images to become huge on those systems with higher pixel density.
See the Providing Resources documentation. Normally I supply for all device screen resolutions I want to support, with the most common being the mdpi/hdpi/xhdpi/xxhdpi folders.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.