close method

Future<void> close()

Closes this app and cleans up all associated resources.

This method:

  1. Removes the app from the global registry
  2. Calls FirebaseService.delete on all registered services
  3. Closes the HTTP client (if it was created by the SDK)
  4. Marks the app as deleted

After calling this method, the app instance can no longer be used. Any subsequent calls to the app or its services will throw a FirebaseAppException with code 'app-deleted'.

Note: If you provided a custom AppOptions.httpClient, it will NOT be closed automatically. You are responsible for closing it.

Example:

final app = FirebaseApp.initializeApp(options: options);
// Use app...
await app.close();
// App can no longer be used

Implementation

Future<void> close() async {
  _checkDestroyed();

  // Remove from registry
  _defaultAppRegistry.removeApp(name);

  // Delete all services
  await Future.wait(
    _services.values.map((service) {
      return service.delete();
    }),
  );

  _services.clear();

  // Only close client if it was initialized AND we created it (not user-provided)
  if (_httpClient != null && options.httpClient == null) {
    (await _httpClient!).close();
  }

  _isDeleted = true;
}