title: Memory leak using Firebase
body: <p>I execute an API call in Firebase for retrieving the user profile information and storing it in a ViewController member variable.
  The API is declared as a static function inside a class MyApi:</p>
  
  <pre><code>// Get User Profile
      static func getUserProfile(byID userId:String,response:@escaping (_ result:[User]?,_ error:Error?)-&gt;()) {
  
          // check ID is valid
          guard userId.length &gt; 0 else {
              print("Error retrieving Creator data: invalid user id provided")
              response(nil,ApiErrors.invalidParameters)
              return
          }
  
          // retrieve profile
          let profilesNode = Database.database().reference().child(MyAPI.profilesNodeKey)
          profilesNode.child(userId).observe(.value, with: { (snapshot) in
              // check if a valid data structure is returned
              guard var dictionary = snapshot.value as? [String:AnyObject] else {
                  print("Get User Profile API: cannot find request")
                  response([],nil)
                  return
              }
  
              // data mapping
              dictionary["key"] = userId as AnyObject
              guard let user = User(data:dictionary) else {
                  print("Get User Profile API: error mapping User profile data")
                  response(nil,ApiErrors.mappingError)
                  return
              }
              response([user], nil)
          }) { (error) in
              response(nil,ApiErrors.FirebaseError(description: error.localizedDescription))
          }
      }
  </code></pre>
  
  <p>and I call it like that:</p>
  
  <pre><code>MyAPI.getUserProfile(byID: creatorId) { (profiles, error) in
              guard let profiles = profiles, profiles.count &gt; 0 else {
                  Utility.showErrorBanner(message: "Error retrieving Creator profile")
                  print("Error retrieving creator profile ID:[\(creatorId)] \(String(describing: error?.localizedDescription))")
                  return
              }
              self.currentProfile = profiles.first!
          }
  </code></pre>
  
  <p>The ViewController is called in Modal mode so it should be deallocated every time I exit the screen.</p>
  
  <p><strong>Problem</strong>: a huge chunk of memory get allocated when I enter the screen, but it doesn't get freed up when I leave it. I'm sure about this because the problem doesn't appear if I remove the line <code>self.currentProfile = profiles.first!</code> (obviously)</p>
  
  <p>How can I avoid this from happening?</p>
  
  <p><strong>NOTE</strong>: <code>currentProfile</code> is of type <code>User</code>, which was used to be a <code>struct</code>. I made it a class so I could use a weak reference for storing the information:</p>
  
  <pre><code>weak var currentCreator: User? {
          didSet {
              updateView()
          }
      }
  </code></pre>
  
  <p>but the problem still persists.</p>