Firebase Storage memory leak when downloading a number of photos from downloadURLs on UICollectionView
<p>I uploaded some photos to Firebase Storage following the <a href="https://github.com/firebase/quickstart-ios/blob/master/storage/StorageExampleSwift/" rel="nofollow">sample project</a> on github.</p>

<p>Before using Firebase Storage, I was saving my photos to some other website. And when I download photos from those image URLs that I saved before on the other website, nothing is wrong and memory usage is reasonable. But when I paste images' URL links to corresponding childs on Firebase Database and then download from those URLs, I seem to have a terrible memory issue. For every ~200kb image, memory usage goes ~10mb up. Since I don't have this problem downloading images from other URLs, I believe this is a firebase specific issue. Does anyone else encounter the same memory issue? Any suggestions/help?</p>

<p><strong>NOTE:</strong> I saved the URLs of the images to the firebase realtime database. I download URL links from there and give them to my photo collection view cells. Here is the code I wrote for my photo collection view cells:</p>

<pre><code>class PhotosCollectionViewCell: UICollectionViewCell {

  @IBOutlet weak var imageView: UIImageView!

  private var downloadTask: FIRStorageDownloadTask!

  var imageURL: String! {
    didSet {
      downloadTask = FIRStorage.storage().referenceForURL(imageURL).dataWithMaxSize(1*1024*1024) { (imageData, error) in
      guard error == nil else { print(error); return }
      if let imageData = imageData {
      self.imageView.image = UIImage(data: imageData)
      }
//      imageView.kf_showIndicatorWhenLoading = true
//      imageView.kf_setImageWithURL(NSURL(string: imageURL)!)
      }
    }
  }

  override func prepareForReuse() {
    super.prepareForReuse()
    imageView.image = nil
    //    imageView.kf_cancelDownloadTask()
    downloadTask.cancel()
  }
}
</code></pre>

<p>The only thing I want to solve is that I want to be able to download the images that I saved to Firebase Storage from their URLs that I also save in the real time database. One important fact is that kingfisher downloads images from URLs without having any memory issue. The problem just occurs when those image URLs are from firebase storage. </p>

<p><strong>NOTE:</strong> I also get memory issue when download those images from Firebase Storage function. I know to some extent it's normal for memory usage to go up but my images in Firebase Storage are just about 200KB.</p>