I'm currently creating an Android application that uses a prepackaged database. The database is initially around 40MB in size and is stored in the assets/databases folder.
The Problem
When I look up how much space my application is using, the "App Info" page shows the following:
- App Size: ~25mb
- User Data: ~3mb
- Cache: ~45mb
I believe that ROOM is causing this because of the following reasons:
- I'm not caching anything in my application (Double checked using the Device File Explorer).
- This problem started happening when I migrated from SQLiteOpenHelper to Room
- The size of the database is much greater than the App Size, but it is around the same as the Cache size so whatever is stored as Cache must be related to the database.
- Whenever I add/remove indices from my Entities, the Cache size changes.
- When I clear the cache and open the app, the Cache size reverts back to ~45mb.
Is it normal for Android ROOM to be storing the prepackaged database as Cache? Any help would be much appreciated and let me know if you need more information.
Thank you
EDIT (Additional Information)
This is what I see in the Device File Explorer
And this is how I'm implementing the Room database
@Database(entities = {/* entities*/}, version = 1, exportSchema = false)
public abstract class MyDatabase extends RoomDatabase {
public abstract MyDao myDao();
private static volatile Database INSTANCE;
public static Database getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (MyDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
MyDatabase.class, "database")
.createFromAsset("databases/database.db")
.build();
}
}
}
return INSTANCE;
}
}


I believe that what you are experiencing may be due to either:
inMemoryDatabaseBuilderorMost likely the latter.
The difference being that in journal mode a log is kept of the changes made to the database, so the database grows as an when changes are applied and new pages are required. Whereas in WAL mode changes are applied to the -wal file and at points (CHECKPOINTs) the changes are then applied to the database file. So until a CHECKPOINT takes places all of the changes are stored in the -wal file.
e.g.

the -shm file is a WAL file for the WAL file
perhaps refer to https://sqlite.org/wal.html
Swapping to an inMemory database (with no other changes, so inserting exactly the same data) then :-
So I suspect that the -wal file is being considered as cache.