Reputation: 6465
I have created an app in which users will be able to upload the images and they can also see all the images uploaded by other users. I have integrated the code for the pagination and downloading the 10 images at a time and showing them on the UITableView. I have used AFNetworking for this task which is saving the image in the cache memory. The problem is that when user keeps downloading the images and count goes to around 300 images, app crashes because the device runs out of memory. I am looking for the best solution of this issue. What I have thought is to keep 50 images in the cache at a time and when user downloads the newer images, older ones will be deleted from the cache. Please also let me know if I can do this with AFNetworking.
Upvotes: 2
Views: 386
Reputation: 71
Try APSmartStorage. You can manage number of images stored in memory. And if 'memory warning' occurred images will be removed from memory. But anyway it's ok because all images stored in files, so you don't need to reload them from network.
Upvotes: 1
Reputation: 1580
You should use SDWebImage instead of downloading images it will cache and you can customise that caching option also .
Iam using this SDWebImage for caching 150 +images in UICollectionview and same in UITableview and its work perfect.
Initially we need to add a placeholder then it will appear one by one.
implementation
1.Take out the SDWebImage code SDWebImage
2.Import the header file in to your viewcontroller
#import <SDWebImage/UIImageView+WebCache.h>
3.then add a single line of code inside cellforrowindex() method. i will gve you example code snaps
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
Upvotes: 2
Reputation: 32240
As @Aklesh Rathaur mentioned in comments, you could try SDWebImage, which is also used by Facebook on their mobile app.
It does a pretty good job at caching and freeing memory when more memory is required. Quoting How is SDWebImage better than X?
On the other side, SDWebImage caches the UIImage representation in memory and store the original compressed (but decoded) image file on disk. UIImage are stored as-is in memory using NSCache, so no copy is involved, and memory is freed as soon as your app or the system needs it.
Let us know your results :-)
Upvotes: 0