我遇到了 RecyclerView 在启动时加载所有项目并触发 200 多个图像加载的问题,这会导致 OutOfMemoryException。
@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.items, parent, false);
Holder holder = new Holder(view);
return holder;
}
我使用 RecyclerView.ViewHolder 为适配器设置项目的常用方法。
在三星 Galaxy S4 上遇到:GT-I9506 - Android-version 5.0.1
还有人发现这个问题吗?在其他设备上也遇到过。
编辑
例外:
09-20 07:35:59.666 25016-25889/smartapp E/art: Throwing OutOfMemoryError "Failed to allocate a 172 byte allocation with 8 free bytes and 8B until OOM" (recursive case)
09-20 07:35:59.686 25016-25889/smartapp E/art: "Picasso-/image-url” prio=5 tid=45 Runnable
09-20 07:35:59.686 25016-25889/smartapp E/art: | group="main" sCount=0 dsCount=0 obj=0x133ad0e0 self=0xad5df000
09-20 07:35:59.686 25016-25889/smartapp E/art: | sysTid=25889 nice=10 cgrp=apps/bg_non_interactive sched=0/0 handle=0xad52e300
09-20 07:35:59.686 25016-25889/smartapp E/art: | state=R schedstat=( 906109587 479948169 1066 ) utm=73 stm=17 core=1 HZ=100
09-20 07:35:59.686 25016-25889/smartapp E/art: | stack=0x92c56000-0x92c58000 stackSize=1036KB
09-20 07:35:59.686 25016-25889/smartapp E/art: | held mutexes= "mutator lock"(shared held)
09-20 07:35:59.686 25016-25889/smartapp E/art: at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:163)
09-20 07:35:59.686 25016-25889/smartapp E/art: at java.io.BufferedInputStream.read(BufferedInputStream.java:295)
09-20 07:35:59.686 25016-25889/smartapp E/art: at com.squareup.picasso.MarkableInputStream.read(MarkableInputStream.java:138)
09-20 07:35:59.686 25016-25889/smartapp E/art: at com.squareup.picasso.Utils.isWebPFile(Utils.java:324)
09-20 07:35:59.686 25016-25889/smartapp E/art: at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:122)
09-20 07:35:59.686 25016-25889/smartapp E/art: at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
09-20 07:35:59.686 25016-25889/smartapp E/art: at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
09-20 07:35:59.686 25016-25889/smartapp E/art: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
09-20 07:35:59.686 25016-25889/smartapp E/art: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-20 07:35:59.686 25016-25889/smartapp E/art: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-20 07:35:59.686 25016-25889/smartapp E/art: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-20 07:35:59.686 25016-25889/smartapp E/art: at java.lang.Thread.run(Thread.java:818)
09-20 07:35:59.686 25016-25889/smartapp E/art: at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
09-20 07:35:58.746 25016-25016/smartapp D/Picasso: Main created [R373] Request{https://image-url}
09-20 07:35:58.746 25016-25016/smartapp D/Picasso: Main created [R374] Request{https://image-url}
09-20 07:35:58.746 25016-25216/smartapp D/Picasso: Dispatcher enqueued [R373]+1ms
09-20 07:35:58.746 25016-25216/smartapp D/Picasso: Dispatcher enqueued [R374]+1ms
09-20 07:35:58.746 25016-25016/smartapp D/Picasso: Main created [R375] Request{https://image-url}
09-20 07:35:58.786 25016-25889/smartapp I/art: Clamp target GC heap from 143MB to 128MB
09-20 07:35:58.786 25016-25889/smartapp I/art: Alloc partial concurrent mark sweep GC freed 622(21KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 127MB/128MB, paused 891us total 54.100ms
09-20 07:35:58.846 25016-25889/smartapp I/art: Clamp target GC heap from 143MB to 128MB
09-20 07:35:58.846 25016-25889/smartapp I/art: Alloc concurrent mark sweep GC freed 17(704B) AllocSpace objects, 0(0B) LOS objects, 0% free, 127MB/128MB, paused 826us total 54.652ms
09-20 07:35:58.846 25016-25889/smartapp I/art: Forcing collection of SoftReferences for 2MB allocation
09-20 07:35:58.846 25016-25036/smartapp I/art: WaitForGcToComplete blocked for 120.065ms for cause Background
09-20 07:35:58.846 25016-25891/smartapp I/art: WaitForGcToComplete blocked for 132.562ms for cause Alloc