I am using Firebase to host and download images for my app. Each image on Firebase ranges from 200kb-400kb, and the user downloads about 12 at a time as they scroll through a collectionView. When I launch the VC that downloads the images, my app goes from using about 100mb of memory to 650mb of memory from downloading 19 images total. The images in questions are JPEGs and have been compressed quite heavily before their upload to Firebase. These images are stored in an NSCache, and clearing the cache brings the memory usage back down to around 100mb.
What is going on? Here is some code that may help?:
class TripOverviewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
func updateUI(photo:Photo, image:UIImage? = nil) {
//Call when preparing to show image
if image != nil {
print("Loaded from cache")
imageView.image = image
photo.assignImage(image: image!)
} else {
let url = photo.imageUrl
let ref = FIRStorage.storage().reference(forURL: url)
ref.data(withMaxSize: 5*1024*1024, completion: { [weak self] (data, error) in
if error != nil {
print("Unable to download image")
} else {
print("Image downloaded")
if let imageData = data {
if let image = UIImage(data: imageData) {
self?.imageView.image = image
photo.assignImage(image: image)
TripsVC.imageCache.setObject(image, forKey: photo.uid as NSString)
}
}
}
})
}
}
}