EllieBubbles
EllieBubbles

Reputation: 133

Glide clear() method can't be resolved

I am trying to fix OutOfMemoryException's in my Android app, in my recyclerView I want to write:

@Override
public void onViewRecycled(final ViewHolder viewHolder) {
    Glide.clear(viewHolder.getImageView());
}

But I get the error:

error: cannot find symbol method clear(ImageView)

I am using:

implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'

Upvotes: 13

Views: 9433

Answers (1)

Mojtaba Haddadi
Mojtaba Haddadi

Reputation: 1376

according to the documentation for clear method.

/**
   * Cancel any pending loads Glide may have for the view and free any resources that may have been
   * loaded for the view.
   *
   * <p> Note that this will only work if {@link View#setTag(Object)} is not called on this view
   * outside of Glide. </p>
   *
   * @param view The view to cancel loads and free resources for.
   * @throws IllegalArgumentException if an object other than Glide's metadata is put as the view's
   *                                  tag.
   * @see #clear(Target)
   */
  public void clear(@NonNull View view) {
    clear(new ClearTarget(view));
  }

therefor your OutOfMemoryException will be handeled by clear method.

and change your code a little , pass context to Glide :

Glide.with(viewHolder.getImageView().getContext()).clear(viewHolder.getImageView());

Upvotes: 5

Related Questions