Out Of Memory Error When Loading More Images In Glide
Solution 1:
I solved this issue by removing nested scroll view placed above recyclerview. Why OutOfMemory error occurred means, when loading more than 200 images in home page, it is loading all 200 images because of using nested scroll view above recyclerview.
So I can't check the logcat image view width and height one by one in adapter.
After removed nested scroll view fixed out of memory error.because it will load only 3 images displayed in device when coming to home activity.
Also check this, how to use scroll instead of nested scroll view.
Solution 2:
This is not an exact solution to your problem, but you need to keep these things in mind while loading images in a list using Glide.
The main threatening part of your problem is the image size. The image you're getting is almost 1mb each! Which is in fact too large for displaying them into a list having 300+ items. So if you're doing the server side too, its always recommended to have the images in several different sizes.
For example, in case of showing a friend list along with their profile pictures, I would suggest you get the whole list first from the server. Then fetch all of the profile images and store them locally. Then populate the ListView
. And the most important part is while uploading a profile picture of an user to the server, after uploading it, the server needs to keep several sizes of it e.g. low, mid and high res version. So that while serving the profile picture urls for the ListView
the server might provide the images with low res as they'll be used most likely for thumbnails.
Using RecyclerView
instead of ListView
is a good call too. But it won't solve the problem you've here when you're in a low-end device.
OMM
has nothing to do with you can solve programatically. You need to resize your image to a lower res version.
You can check for the Glide's caching mechanism too. I would suggest you use the caching strategy so that every time you don't have to load the image from server.
Good luck.
Solution 3:
Using Glide doesn't guarantee no Out of Memory
errors, you need to use several small steps to reduce the probability to not get OOM's
.
Step 1: Understand the caching mechanism in Glide
Step 2: I prefer to load thumbnails
into recyclerview
Glide
.with( context )
.load( UsageExampleGifAndVideos.gifUrl )
.thumbnail( 0.1f )
.into( imageView2 );
Remember to always request small size image if bigger or HD images are not required.
Solution 4:
- Make sure the ImageView has match_parent or fixed dp as dimensions wrap_content makes Glide load full resolution Bitmaps.
- .placeholder() shows an image instead of empty space while loading large bitmap
- .thumbnail(float) loads a downsampled version fast while the bigger image is loading in the background
- Also look around the Glide issues, maybe you find something helpful.
Solution 5:
Use recyclerView
instead of ListView
. It reusable single item for rendering items. I am using glide
with recyclerView
where i am loading wallpapers with 100+ items.
In ListView every time you are creating view, if you have 100+ view and it will create 100+ views where as in recyclerview it creates how many visible items are there in screen +2.
Post a Comment for "Out Of Memory Error When Loading More Images In Glide"