1

有人可以在这里向我解释评论

调用 Picasso 时不要创建匿名的 Target 类,因为可能会被垃圾收集。保留成员字段作为强引用,以防止它被 gc'ed

根据ImageViewAction.java 的第 30 行,Callback 是一个强引用。

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;
  }

假设 Callback 是一个匿名类,它将创建对其父类的引用,从而防止父类也被 GC'd。

根据Action.java 的第 48 行,目标本身是一个 WeakReference,但这不是回调。

  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);

有人可以解释我的误解吗?

4

1 回答 1

0

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

于 2013-12-11T05:33:13.693 回答