Android 匿名类如何获得GC';安卓上毕加索的d?

Android 匿名类如何获得GC';安卓上毕加索的d?,android,anonymous-inner-class,picasso,Android,Anonymous Inner Class,Picasso,谁能给我解释一下: 调用毕加索时尽量不要创建匿名目标类 把垃圾收集起来。保留一个成员字段作为对 防止它被gc'ed 根据,该回调是一个强引用 ImageViewAction(Picasso picasso, ImageView imageView, Request data, boolean skipCache, boolean noFade, int errorResId, Drawable errorDrawable, String key, Callback callback)

谁能给我解释一下:

调用毕加索时尽量不要创建匿名目标类 把垃圾收集起来。保留一个成员字段作为对 防止它被gc'ed

根据,该回调是一个强引用

ImageViewAction(Picasso picasso, ImageView imageView, Request data, boolean skipCache,
      boolean noFade, int errorResId, Drawable errorDrawable, String key, Callback callback) {
    super(picasso, imageView, data, skipCache, noFade, errorResId, errorDrawable, key);
    this.callback = callback;
  }
假设回调是一个匿名类,它将创建对其父类的引用,从而防止父类也被GC调用

根据,目标本身是一个弱引用,但这不是回调

  Action(Picasso picasso, T target, Request data, boolean skipCache, boolean noFade,
      int errorResId, Drawable errorDrawable, String key) {
    this.picasso = picasso;
    this.data = data;
    this.target = new RequestWeakReference<T>(this, target, picasso.referenceQueue);
Action(毕加索、毕加索、T目标、请求数据、布尔skipCache、布尔noFade、,
int ERRORRISD,Drawable ERRORRAWABLE,字符串键){
毕加索=毕加索;
这个数据=数据;
this.target=newrequestweakreference(this,target,picasso.referenceQueue);

有人能解释我误解了什么吗?

我很困惑,评论提到了目标(ImageView)不是回调。使用匿名回调的模式很好。

必须有人持有对您的
目标的引用
,否则它会被gc'ed,因为毕加索只存储了对它的
WeakReference
。啊,我明白了-您的评论只应用于目标,而不是回调。那么使用匿名回调应该可以,是的?是,匿名回调保留为强引用。强烈建议您调用
cancel(target)
以释放引用并防止临时泄漏,直到毕加索下载完成。