[問題] viewPager Imageview OOM
大家好
最近用了viewPager + FrameLayout 可以玩玩相簿,
但不斷的出現OOM已經快瘋掉了,
已經使用AsyncTask處理了大圖片溢出的問題,
(BitmapFactory.Options options;
options.inSampleSize = 2;
......)
主要會有問題的地方,是當imageview.setImageBitmap(Bmp)後
,會暫存住bitmap,在PagerAdapter有提供
destroyItem(View container, int position, Object object)
讓我recycle掉存在imageview裡的bitmap
imageview.setImageDrawable(null);
if(oldBitmap !=null && !oldBitmap.isRecycled())
{
oldBitmap.recycle();
oldBitmap = null;
}
我以為這樣已經可以將bitmap給清除乾淨,但是當換了多張圖片後
,還是出現了oom的問題(Caused by: java.lang.OutOfMemoryError:
(Heap Size=98304KB, Allocated=91403KB),想請問各位,該如何解決呢?
(ps. 突然想到會不會有可能是,ViewPager 每滑動一次,所以新增一個view
所以除了刪除舊有的bitmap 舊有的view 也須手動刪除?)
謝謝大家
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.138.152.10
※ 文章網址: http://www.ptt.cc/bbs/AndroidDev/M.1402380627.A.711.html
※ 編輯: fake01 (140.138.152.10), 06/10/2014 14:18:29
→
06/10 14:24, , 1F
06/10 14:24, 1F
→
06/10 14:25, , 2F
06/10 14:25, 2F
推
06/10 16:50, , 3F
06/10 16:50, 3F
→
06/10 17:20, , 4F
06/10 17:20, 4F
→
06/10 17:23, , 5F
06/10 17:23, 5F
→
06/10 17:24, , 6F
06/10 17:24, 6F
推
06/10 18:31, , 7F
06/10 18:31, 7F
→
06/10 18:32, , 8F
06/10 18:32, 8F
推
06/10 21:52, , 9F
06/10 21:52, 9F
→
06/10 21:54, , 10F
06/10 21:54, 10F
→
06/10 21:55, , 11F
06/10 21:55, 11F
→
06/10 21:55, , 12F
06/10 21:55, 12F
→
06/10 21:58, , 13F
06/10 21:58, 13F
→
06/10 21:58, , 14F
06/10 21:58, 14F
→
06/10 21:59, , 15F
06/10 21:59, 15F
討論串 (同標題文章)