Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make [load on scroll] to not keep adding images into ram?

I'm doing some load on scroll in my UITableView to fetch data from the server.

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{
    let lastElement = self._titles_en.count - 1
    if indexPath.row == lastElement
    {
        page += 1
        searchForString()
    }
}

each entry adds a UITableViewCell with a UIImageView loaded using kingfisher

loadRemoteImage(placeImage, argURL: _images[indexPath.row], cr : 0)

Now my question is, how do I make sure that the ram used don't keep on increasing?

I was watching the ram in debug tools, it increases by 10 mega bytes for about 3 page loads, which is too much, and it's starting to exceed 200 mega bytes, so is there any trick to avoid this ram open increase? I'm afraid of the user keeping scrolling many times and boom, app crash.

like image 379
DeyaEldeen Avatar asked Sep 25 '16 17:09

DeyaEldeen


2 Answers

I'd say optimize your images, a lot. According to what you're saying, you're using very large images. Remember that they are being displayed in a UITableViewCell, so it should be safe to have them compressed.

Try fetching and displaying thumbnails instead of the actual full-sized images. That would improve user experience too, reduce lag, your memory usage!

like image 129
Joe Avatar answered Oct 19 '22 14:10

Joe


You can use AsyncDisplayKit and automatically benefit from intelligent preloading and memory management. In particular, if a cell of an ASTableNode includes an image, but that cell is not likely to be visible soon then the image will be purged from memory.

example : example

like image 31
skensell Avatar answered Oct 19 '22 13:10

skensell