Out Of Memory Error When loading more images in Glide

前端 未结 11 999
我寻月下人不归
我寻月下人不归 2020-12-31 06:32

Edited:

  • In my application, I am loading more than 300 images in home page. I used glide to load images. I\'m getting Out of
11条回答
  •  半阙折子戏
    2020-12-31 06:57

    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.

提交回复
热议问题