How to Close Realm Database
Jun 10, 2019
According to Official Documentation, always close the realm instance when you done with them.
Best Practise Close Instance
1 | try { |
if you useminSdkVersion >= 19andJava >= 7, you won’t close it manually.
1 | try (Realm realm = Realm.getDefaultInstance()) { |
Getting the above answer from the this stackoverflow answer
Kotlin
The try (Realm realm = Realm.getDefaultInstance()) in Java is called try-with-resource. This is how we do in Kotlin:
1 | Realm.getDefaultInstance().use { |
Note: You have to use minSdkVersion >= 19andJava >= 7 in order to not close it manually.
