I'm just getting to know about Android Room Database.
When I was using Realm Database, I had to care if Realm DB instance was opened or closed.
So I managed it by .use in my kotlin code.
RealmProvider(context).getDatabase().use { database ->
if (database == null) {
it.onError(Exception("DataBase Open Error !"))
} else {
database.executeTransaction { realm -> realm.insert(SomeData) }
it.onComplete()
}
}
However; in Room DB, no one use roomDatabase.close() in their codes.
So I'm wondering when Room DB is closed and opened and also when db instance is allocated and free on RAM memory.
No, according to https://stackoverflow.com/a/7739454/1090523 the system will handle the closing of the database connection when the app is closed. No leak will occur, and it is also more performant to keep a connection open and reuse it than to keep opening and closing connections.
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