3

I'm using fragments in a ViewPager, each page is having imageviews. I'm following databinding rules and i load image using Glide in BindingUtils. Now issue is that when i call Glide.clearMemory() in onDestroyView of fragment. It doesn't clear memory and heap keeps on growing.

BindingUtils:

@BindingAdapter("imageUrl")
    public static void setImageUrl(ImageView imageView, String url) {
        Context context = imageView.getContext();
        if (url != null) {
            Glide.with(context).load(url).load(url))
                    .into(imageView);
   }
    }

From Fragment:

@Override
    public void onDestroyView() {
        if (getContext() != null)
            Glide.get(getContext()).clearMemory();
        super.onDestroyView();
    }

I checked a this answer at stackoverflow, and it states that imageView.getContext(); gives application context and when we release memory from fragment then it has fragment context. So, question is that how can i get the related context and release the memory then? Any ideas would be appreciable.

Usman Rana
  • 2,067
  • 1
  • 21
  • 32

0 Answers0