David Corsalini
David Corsalini

Reputation: 8208

Realm open/close practice

How bad is it to open a Realm instance in the app onCreate and leave it open for the whole Application lifecycle, only closing it when the application is killed? (assuming I won't call it from another thread)

Upvotes: 4

Views: 1864

Answers (1)

Christian Melchior
Christian Melchior

Reputation: 20126

It is perfectly safe to do, but if you don't close the Realm when your app goes in the background there is a higher chance your app will be killed by the system when it needs to reclaim resources.

You can also read about controlling the lifecycle here: https://realm.io/docs/java/latest/#controlling-the-lifecycle-of-realm-instances

Upvotes: 2

Related Questions