title: Loading GIFs using SDWebImage is taking up far more memory than anticipated
body: <p>I am building a UITableView populated with images and GIFs downloaded using SDWebImage. The images are shown in the table cells, whereas the GIF are shown as a 3D touch preview.</p>
  
  <p>The problem is that every time a GIF is previewed the memory spikes (as expected) however the memory use increases far more than I thought it would. Downloading one of the GIFs manually, I found that it's only around 500kB, but when doing it in the app through SDWebImage, sethe memory increase is closer to 100MB.</p>
  
  <p>After just a few GIF previews the app crashes due to memory issues...</p>
  
  <p>At first I thought perhaps the instance of GIFView was not being deallocated when the GIF preview was exited - I checked with '''deinit''' and it does seem to be deallocating.</p>
  
  <p>I also reset the GIFView to '''nil''' in viewDidDisappear but that did not help either. </p>
  
  <p>Looking at the Allocations Instrument, I found that the GIFs are being permanently stored in memory when they are first loaded. This explains why viewing the same GIF again does not increase the memory.</p>
  
  <p>Does anyone see why these GIFs are taking so much memory? I also built a version of the app where all the assets were local and that ran smoothly with no hiccups or memory issues - but surely the GIF sizes should be the same size in both cases?! </p>
  
  <p>If there is no leak and these memory spikes are inevitable, is there any other way of clearing the GIF from memory when it disappears?</p>
  
  <p>Code is below</p>
  
  <pre><code>//model
  struct Visualisation: Codable {
      var id: Int
      let name, info, url_name, tags, imageURL, gifURL: String
  }
  
  //3D touch GIF preview
  extension ViewController: UIViewControllerPreviewingDelegate {
  
      func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -&gt; UIViewController? {
  
          guard let indexPath = tableView.indexPathForRow(at: location) else { return nil }
          let selectedVis = filteredVisualisations[indexPath.row]
  
          let identifier = "GIFViewController"
          guard let GIFVC = storyboard?.instantiateViewController(withIdentifier: identifier) as? GIFViewController else { return nil}
  
          GIFVC.selection = selectedVis
  
          GIFVC.preferredContentSize = CGSize(width: 0, height: 190)
  
          return GIFVC
      }
  
  //GIFViewController
  
  import UIKit
  import SDWebImage
  
  class GIFViewController: UIViewController {
  
      @IBOutlet weak var GIFView: UIImageView!
  
      var selection = visualisations[0]
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          GIFView.sd_setImage(with: URL(string: selection.gifURL))
  
          // Do any additional setup after loading the view.
      }
  
      override func viewDidDisappear(_ animated: Bool = true) {
      }
  
      deinit {
          print("DEALLOCATED GIFViewController class")
      }
  
  }
  
  
  //setting the table cells
  class TableViewCell: UITableViewCell {
  
      @IBOutlet weak var ImageView: UIImageView!
      @IBOutlet weak var TitleLabel: UILabel!
      @IBOutlet weak var InfoLabel: UILabel!
  
      func setCell(visualisation: Visualisation){
  
          ImageView.sd_setImage(with: URL(string: visualisation.imageURL))
          TitleLabel.text = visualisation.name
          InfoLabel.text = visualisation.info
      }
  }
  </code></pre>
  
  <p>Any help would be much appreciated.</p>
  
  <p>P.S. I am sure you've already noticed that I am very new to iOS development... Pardon my 'newbieness'...</p>