ImageLoader- java.lang.OutOfMemoryError

53691 ワード

提案: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が私に10対15の画像が好きになって、その例外を渡してくれました.
 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)

ベストアンサー
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