What is the perfect use case for using Room.inMemoryDatabaseBuilder()?



So I am creating this application where there are lots of personal information and data which shouldn’t be persisted in the device to avoid security issues. When learning about Room, I came across this Room.inMemoryDatabaseBuilder() which as the documentation states:

Creates a RoomDatabase.Builder for an in memory database. Information stored in an in memory database disappears when the process is killed. Once a database is built, you should keep a reference to it and re-use it.

I was wondering whether this would be a perfect usecase for my situation. Since the data will only exist in memory and not stored in the device.

It seems like a good idea. My only concern is that I haven’t seen an implementation of this in an actual application yet. The only usecase which I saw this Room.inMemoryDatabaseBuilder() used was for testing (so then you don’t have to worry about database clean-up on each and every test run).

Can anyone offer some advice? It would be much appreciated.

Thank you very much.


I posted this same context question in @Florina Muntenescu Blog here

Her answer was:

Yes, it can be used for any use case that requires the data to be kept in memory only. Testing is one of them.

So basically, Room.inMemoryDatabaseBuilder() can be used for other use cases where data should only be kept in memory.

Answered By – Archie G. Quiñones

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More