My app uses firebase\'s observeSingleEventOfType quite a fair bit and I came to realise that my app\'s memory increase over time. I have commented out all my code except a test
This is likely only happening because you are running on debug build. My results, after ~128 clicks on device with a debug build:
As you can see, the vast majority of memory consumption is due to performance tools related to debugging. You can disable this feature if you'd like to confirm it, by editing your scheme:
And then disabling backtrace recording:
With it disabled, the same ~128 clicks shows essentially no growth:
Granted, you may not want to leave that disabled, as you may find it useful for diagnosing crashes and other issues in your debug builds. It shouldn't be a problem in a release build though!
For reference, this was the code I was running:
import UIKit
import FirebaseDatabase
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
private var count: Int = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func testBtnPressed(sender: AnyObject) {
let db = FIRDatabase.database().reference()
db.child("posts").observeSingleEventOfType(.Value) { [weak self] (snap: FIRDataSnapshot!) in
guard let this = self else { return }
this.count = this.count + 1
this.label.text = "\(this.count)"
}
}
}