1

In my app, I have a problem with the memory.

If I write ref.getDocuments() everything works fine. The memory stay at 40mo. However, if I add .whereField("movementID", isEqualTo: PRID) the memory go from 40mo to more than 1Go ...

ref.whereField("movementID", isEqualTo: PRID).getDocuments() { (querySnapshot, err) in
         if let err = err {
            print("Error getting documents: \(err)")
         } else {
            if querySnapshot!.isEmpty {
               print("EMPTY")
            }
            for document in querySnapshot!.documents {

               let dict = document.data()
            }
         }         
}

I call this function multiple times, so if the function is called 15-20 times the memory goes to 1Go, but if it's more, the app crash.

Do you have an idea about why there is this memory issue, and how I could correct the problem?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
KevinB
  • 2,454
  • 3
  • 25
  • 49
  • I can't tell from the limited code above, but I suspect there may be a [strong reference cycle](https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html#//apple_ref/doc/uid/TP40014097-CH20-XID_61) Try using `unowned self` in the closure, as described in [this question](https://stackoverflow.com/questions/24320347/shall-we-always-use-unowned-self-inside-closure-in-swift). If there is no change, I suggest you reach out to [Firebase support](https://firebase.google.com/support/troubleshooter/). – Jen Person Apr 18 '19 at 14:34

0 Answers0