compact static method
Compacts a Realm file. A Realm file usually contains free/unused space.
This method removes this free space and the file size is thereby reduced. Objects within the Realm file are untouched. Note: The file system should have free space for at least a copy of the Realm file. This method must not be called inside a transaction. The Realm file is left untouched if any file operation fails.
Implementation
static bool compact(Configuration config) {
if (config is InMemoryConfiguration) {
throw RealmException("Can't compact an in-memory Realm");
}
if (!Realm.existsSync(config.path)) {
print("realm file doesn't exist: ${config.path}");
return false;
}
final realm = Realm(config);
try {
return realm.handle.compact();
} finally {
realm.close();
}
}