Docs Menu

Open & Close a Realm - Flutter SDK

On this page

  • Open a Realm
  • Open a Read-Only Realm
  • Open an In-Memory Realm
  • Set Custom FIFO Special Files
  • Close a Realm

Use the Configuration class to control the specifics of the realm you would like to open, including schema.

Pass your configuration to the Realm constructor to generate an instance of that realm:

var config = Configuration([Car.schema]);
var realm = Realm(config);

You can now use that realm instance to work with objects in the database.

You can open an existing realm in read-only mode. To open a read-only realm, add readOnly: true to your Configuration object.

You can only open existing realms in read-only mode. If you try to write to a read-only realm, it throws an error.

var config = Configuration([Car.schema], readOnly: true);
realm = Realm(config);

To create a realm that runs entirely in memory without being written to a file, add inMemory: true to your Configuration object. In-memory realms cannot also be read-only.

var config = Configuration([Car.schema], inMemory: true);
var realm = Realm(config);

Set a value for Realm's FIFO special files location. Opening a realm creates a number of lightweight FIFO special files that coordinate access to the realm across threads and processes. If the realm file is in a location that doesn't allow for the creation of FIFO special files (such as FAT32 filesystems), then the realm cannot be opened. In this case, Realm needs a different location to store these files. Add fifoFilesFallbackPath: <Your Custom FIFO File Path> to your Configuration object.

This property is ignored if the directory for the realm file allows FIFO special files.

var config =
Configuration([Car.schema], fifoFilesFallbackPath: "./fifo_folder");
var realm = Realm(config);

Once you've finished working with a realm, close it to prevent memory leaks.

←  Define a Realm Object Schema - Flutter SDKRead & Write Data - Flutter SDK →
Give Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.