使用Picaso在recyclerview中使用Android OOM(内存不足)

时间:2018-03-16 11:48:11

标签: android android-recyclerview

这是recyclerview adpater onBindViewHolder方法,每次我进行rquest时,我都会获得10个元素添加到List并通知dapater,这很好但是在4或5次调用后我的应用程序在PICASO获取图像时崩溃,并导致内存不足例外

 public void onBindViewHolder(ViewHolder holder, int position) {
    try {
    //okhttp client
     OkHttpClient client = new OkHttpClient();

    //okhttp downloader
     OkHttp3Downloader downloader = new OkHttp3Downloader(client);
     //picaso fetch the image  set to image view , width 500 ,height 100 
     picasso = new Picasso.Builder(context).downloader(downloader).build();
        picasso.load(recordList.get(position).getImageUri())
                .error(R.drawable.golootlo_placeholder_nearby)
                .placeholder(R.drawable.golootlo_placeholder_nearby)
                .fit()
                .into(holder.imageViewBanner);
    }catch (Exception e){
        System.out.print(e.getMessage());
    }

    /*rest of view are getting value here from List object*/
}

0 个答案:

没有答案