I decided to use Firebase as the backend for an app I am making. One thing I realized is that the network connection to Firebase does not close once my data for the table view is populated.

Is there a way I can close the connection so it doesn't drain my users data? In my code where I get the data, I store it locally so it would still be there.

```
    class HomeTableViewController: UITableViewController{

    //firebase refrences
    var restaurantArray = [Restaurant]()

    var dataBaseRef: FIRDatabaseReference! {
        return FIRDatabase.database().reference()
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Home"
        navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "menuIcon"), style: .plain, target: self, action: #selector(SSASideMenu.presentLeftMenuViewController))
        navigationItem.leftBarButtonItem?.setBackButtonBackgroundImage(#imageLiteral(resourceName: "backButton"), for: .normal , barMetrics: .default)

        tableView.backgroundView = UIImageView(image: UIImage(named: "Background"))
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        fetchRestaurants()
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    func fetchRestaurants(){
       dataBaseRef.child("AthensRestaurants/Restaurants").observe(.value, with: { (snapshot) in
            var results = [Restaurant]()

            for res in snapshot.children{
                let res = Restaurant(snapshot: res as! FIRDataSnapshot)
                results.append(res)
            }

            self.restaurantArray = results.sorted(by: { (u1, u2) -> Bool in
                u1.name < u2.name
            })
            self.tableView.reloadData()
            self.dataBaseRef.removeAllObservers()
    }) { (error) in
    print(error.localizedDescription)
    }
}
      // MARK: - Table view data source
      // MARK: - Table view data source

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return restaurantArray.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "restaurantsCell", for: indexPath) as! RestaurantsTableViewCell

        // Configure the cell...

        cell.configureCell(res: restaurantArray[indexPath.row])
        cell.backgroundColor = UIColor.clear
        cell.contentView.layer.borderColor = UIColor.clear.cgColor
        cell.contentView.layer.borderWidth = 1.5
        return cell
    }

    //transfers data to new page
    func showRestaurantViewControllerWith(_ res: Restaurant) {
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let destinationVC = storyBoard.instantiateViewController(withIdentifier: "RestaurantDetails") as! RestaurantDetailViewController
        destinationVC.resTransfer = res
        self.navigationController?.pushViewController(destinationVC, animated: true)
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.showRestaurantViewControllerWith(self.restaurantArray[indexPath.row])
    }

}

```