在上述代码中,Glide 加载图片所占用的内存是通过 CustomTarget
的 onResourceReady
方法返回的 Drawable
对象来表示的。因此,在 onViewRecycled
方法中,我们可以通过将 Drawable
对象的引用置为 null
来释放所占用的内存。
具体来说,我们可以将 CustomTarget
对象声明为 ViewHolder 的成员变量,并在 onViewRecycled
方法中将其引用置为 null
,以释放 Drawable
所占用的内存。例如:
public class MyViewHolder extends RecyclerView.ViewHolder {
private LinearLayout linearLayout;
private