I'm using Realm for my React Native app. I'm making Realm instances available to my components like this, as shown in the official example app:
export default new Realm({schema: [Todo, TodoList]});
.
When I subsequently ran tests with Jest, I realized that the process didn't finish as long as I wouldn't call
afterAll(() => {
realm.close();
});
at the end of the test suite.
This made me think about if and when I should call realm.close()
in the production code. What are the consequences of not calling close? If recommended, what would be the best way to close Realm instances?
realm.close()
is used when you are done with your current schema. In Realm api page it says the following:
close(): Closes this Realm so it may be re-opened with a newer schema version. All objects and collections from this Realm are no longer valid after calling this method.
If you don't want to change your schema, you don't have to worry about close
method.
Full reference here: Realm close method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With