Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 683
EllieBubbles Avatar asked Apr 29 '18 16:04

EllieBubbles


1 Answers

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());
like image 85
Mojtaba Haddadi Avatar answered Oct 18 '22 18:10

Mojtaba Haddadi