Search code examples
iossdwebimage

SDWebImage give rise to memory to a high value


I don't know if I write a bug or not when I use SDWebImage to load a lot of image from the server, every time I scroll my list(tableview or collectionview), the memory raise to a high value (eg. 200M). this is my code in the cell:

 - (void)loadInfo(NSDictionary *)dic
    {
        self.imgView sd_setImageWithURL:[NSURL URLWithString:dic[@"image_src"]];
    }

I am sure my cell reuse is ok, I want to know this is why, Thanks.


Solution

  • when you're scrolling, you're loading a lot of pictures asynchronously making you have many threads and asynchronous downloads, thus the memory issue. However I suggest the following for you.

    1- don't download high resolution images from the web, choose a default resolution and let your server minimize the resolution before sending the image if possible (saves a lot of memory)

    2- It is a good idea to cache the images so that you don't download them again when their cell appear (SDWebImage provides that cache feature).

    Those 2 steps should make your app okay.

    Hope this helps!