I am using Glide with RecyclerView to load many images (around 200) which have different sizes and dimensions.
I have three problems:
The images sometimes load successfully, and sometimes the app crashes giving OOM.
If the images are loaded successfully, then the scrolling is laggy.
If I refresh the layout and reload the same images, then it tries to load the images but fails before completion and gives OOM.
Following is the relevant code:
public static class MyViewHolder extends RecyclerView.ViewHolder {
@Override
public void onBindViewHolder(final MyViewHolder holder, final int listPosition) {
ImageView imageView = holder.imageView;
Glide.with(imageView.getContext())
.load(tweetMapArray.get(listPosition).get("imageURL").toString())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.crossFade()
.into(imageView);
// imageURL is a valid URL for each item
}
@Override
public void onViewDetachedFromWindow(MyViewHolder holder) {
super.onViewDetachedFromWindow(holder);
Glide.clear(holder.imageView);
}
}
Please guide me as to what I am doing wrong. I have not worked with so many images before.