eysidi
eysidi

Reputation: 21

High memory usage when loading gif using Glide

I'm using Glide to load GIF in my PagerAdapter.

Images are coming from the server with a high resolution and lots of frames.

I noticed that the memory usage is high once the GIFs are loaded and playing and can lead to Out Of Memory.

I tried the following methods of Glide (.override(),skipMemoryCache(),diskCacheStrategy()) but the memory usage did not change.

Are there any other methods in Glide that can be used?

    Glide.with(mContext)
            .load(imageUrl)
            .override(480, 342)
            .listener(new RequestListener<String, GlideDrawable>() {
                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    imageViewBackground.setImageDrawable(resource);
                    return false;
                }
            })
    .into(imageViewBackground);

Upvotes: 2

Views: 801

Answers (2)

Bhoomika Prajapati
Bhoomika Prajapati

Reputation: 714

I am getting this way after many try

Glide.with(mContext)
     .load(media_url)
     .thumbnail(Glide
     .with(mContext)
     .load(media_url)
     .listener(new RequestListener<String, GlideDrawable>() {
                                @Override
                                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                                    progressBar.setVisibility(View.GONE);
                                    return false;

                                }

                                @Override
                                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                    progressBar.setVisibility(View.GONE);
                                    return false;
                                }
                            })
                    )

                    .dontAnimate()
                    .into(mIvMessageImage);

Upvotes: 0

Dan Alboteanu
Dan Alboteanu

Reputation: 10252

    Glide.with(mContext)
        .load(imageUrl)
        .override(480, 342)
        .into(...)

the override did the trick for me and no more RemoteViews for widget update exceeds max bitmap memory usage error

Upvotes: 0

Related Questions