ImageLoader- java.lang.OutOfMemoryError

建议:Android官方给的建议是,作为程序员的我们应该努力减少内存的使用,想回收和复用的方法,而不是想方设法增大内存。当内存很大的时候,每次gc的时间也会长一些,性能会下降呦。


I developing an android app that requires me to display some images by getting it from the server at the run_time, so I get it's thumbnail and then use Android-Universal-ImageLoader to get these images:

 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).build(); ImageLoader.getInstance().init(config); // to get the movie_poster from the server private void setImageResource_season(ImageButton image, String url){ loader = ImageLoader.getInstance(); loader.displayImage(url, image); }

when it's a little amount of images everything goes well, but when it's like about 100 images the ImageLoader gives me likefrom10 to 15 images then it passes me that exception:

 02-19 15:14:30.018: ERROR/dalvikvm-heap(597): Out of memory on a 1382416-byte allocation. 02-19 15:14:30.018: INFO/dalvikvm(597): "uil-pool-1-thread-1" prio=4 tid=16 RUNNABLE 02-19 15:14:30.018: INFO/dalvikvm(597): | group="main" sCount=0 dsCount=0 obj=0x413f6e18 self=0x1e05c8 02-19 15:14:30.018: INFO/dalvikvm(597): | sysTid=649 nice=10 sched=0/0 cgrp=bg_non_interactive handle=2031848 02-19 15:14:30.018: INFO/dalvikvm(597): | schedstat=( 17149851689 41024927609 1804 ) utm=1582 stm=132 core=0 02-19 15:14:30.018: INFO/dalvikvm(597): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 02-19 15:14:30.018: INFO/dalvikvm(597): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:78) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:289) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:245) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141) 02-19 15:14:30.018: INFO/dalvikvm(597): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 02-19 15:14:30.018: INFO/dalvikvm(597): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 02-19 15:14:30.018: INFO/dalvikvm(597): at java.lang.Thread.run(Thread.java:856) 02-19 15:14:30.108: DEBUG/skia(597): --- decoder->decode returned false 02-19 15:15:10.008: ERROR/ImageLoader(597): null 02-19 15:15:10.008: ERROR/ImageLoader(597): java.lang.OutOfMemoryError 02-19 15:15:10.008: ERROR/ImageLoader(597): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 02-19 15:15:10.008: ERROR/ImageLoader(597): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:78) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:289) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:245) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141) 02-19 15:15:10.008: ERROR/ImageLoader(597): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 02-19 15:15:10.008: ERROR/ImageLoader(597): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 02-19 15:15:10.008: ERROR/ImageLoader(597): at java.lang.Thread.run(Thread.java:856)

我开发Android应用程序,我需要让它从服务器在run_time展示一些图片,所以我得到它的缩略图然后使用Android的通用imageloader为了得到这些图像:

 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).build(); ImageLoader.getInstance().init(config); // to get the movie_poster from the server private void setImageResource_season(ImageButton image, String url){ loader = ImageLoader.getInstance(); loader.displayImage(url, image); }

当一个小数量的图像,一切顺利,但当它喜欢的100图像ImageLoader让我喜欢1015图像然后递给我那个例外:

 02-19 15:14:30.018: ERROR/dalvikvm-heap(597): Out of memory on a 1382416-byte allocation. 02-19 15:14:30.018: INFO/dalvikvm(597): "uil-pool-1-thread-1" prio=4 tid=16 RUNNABLE 02-19 15:14:30.018: INFO/dalvikvm(597): | group="main" sCount=0 dsCount=0 obj=0x413f6e18 self=0x1e05c8 02-19 15:14:30.018: INFO/dalvikvm(597): | sysTid=649 nice=10 sched=0/0 cgrp=bg_non_interactive handle=2031848 02-19 15:14:30.018: INFO/dalvikvm(597): | schedstat=( 17149851689 41024927609 1804 ) utm=1582 stm=132 core=0 02-19 15:14:30.018: INFO/dalvikvm(597): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 02-19 15:14:30.018: INFO/dalvikvm(597): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:78) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:289) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:245) 02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141) 02-19 15:14:30.018: INFO/dalvikvm(597): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 02-19 15:14:30.018: INFO/dalvikvm(597): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 02-19 15:14:30.018: INFO/dalvikvm(597): at java.lang.Thread.run(Thread.java:856) 02-19 15:14:30.108: DEBUG/skia(597): --- decoder->decode returned false 02-19 15:15:10.008: ERROR/ImageLoader(597): null 02-19 15:15:10.008: ERROR/ImageLoader(597): java.lang.OutOfMemoryError 02-19 15:15:10.008: ERROR/ImageLoader(597): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 02-19 15:15:10.008: ERROR/ImageLoader(597): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:78) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:289) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:245) 02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141) 02-19 15:15:10.008: ERROR/ImageLoader(597): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 02-19 15:15:10.008: ERROR/ImageLoader(597): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 02-19 15:15:10.008: ERROR/ImageLoader(597): at java.lang.Thread.run(Thread.java:856)

最佳答案 (Best Answer)

Add

 android:largeHeap="true" 

within the application tag into your manifest

Example

 <application android:allowBackup="true" android:largeHeap="true" android:icon="@drawable/ic_launcher" > 参考自:http://www.4byte.cn/question/183043/imageloader-java-lang-outofmemoryerror.html 

你可能感兴趣的:(ImageLoader- java.lang.OutOfMemoryError)