close method

void close()

Closes this store.

Don't try to call any other ObjectBox methods after the store is closed.

Implementation

void close() {
  if (isClosed()) return;

  _boxes.values.forEach(InternalBoxAccess.close);
  _boxes.clear();

  // Call each "onClose()" event listener.
  // Move the list to prevent "Concurrent modification during iteration".
  _onClose.values.toList(growable: false).forEach((listener) => listener());
  _onClose.clear();

  _reader.clear();

  if (!_weak) {
    _openStoreDirectories.remove(_absoluteDirectoryPath);
    final errors = List.filled(2, 0);
    if (_cFinalizer != nullptr) {
      errors[0] = C.dartc_detach_finalizer(_cFinalizer, this);
    }
    errors[1] = C.store_close(_cStore);
    errors.forEach(checkObx);
  }
  _cStore = nullptr;
}