What might be an acceptable solution for handling large amounts of images in memory?
Currently I’m building a photo-sharing application (in some sense similar to Instagram). I’ve been able to mimic their fast loading of many images in the feed (combining pre-loading and lazy-loading of images), but I’m a little stuck on what to do to handle the potential large memory footprint these images will have.
Is CoreData an option for temporary image storage? Is writing the objects to the temporary directory using NSCoder another option? I’m trying to proactively avoid memory crashes, and I’m unsure whether CoreData, a temporary folder, or some other means would be decent enough to reduce the memory footprint of (potentially) hundreds of images if the user scrolls in their feed pretty far. These also will not be permanent.
(For what it’s worth, right now I have an object representation for each image that holds metadata and the image, and they are stored in a basic array structure. It works well for now, but I want to make sure if I’m loading hundreds of images I can reduce the memory footprint but still be able to quickly access these objects)
I’ve run into this exact dilemma as you in a couple of my own apps, where I had to potentially display hundreds of UIImage objects in table views.
One of the solutions I did for my app was to not store the full resolution image in memory but instead a thumbnail (which I shrunk down using the UIImage+Resize.h category extension available and described here). And once the user decided to edit or make use of the photo, I then loaded the entire full resolution image.
You can also save these thumbnails (or at least their image data) to small files in the “
~/Library/Caches/” folders.