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.