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'
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With