Paolo Rotolo
03/10/2023, 2:47 PMdefault.realm
reached 17 GB in one of our apps, even if we don't store a lot of data (there are very frequent writes, but then entities are deleted when in sync with server). We noticed a similar problem on github, so we upgraded realm version to latest one.
Now we're tracking the numberOfActiveVersions
on each write, and we see that the number increases each time a new write is performed (1 write for second). It should be related to this issue: https://github.com/realm/realm-kotlin/issues/1081
We're still performing more tests with latest realm 1.6.1
but, will this issue of always growing realm versions affect database size on disk?
According to github, https://github.com/realm/realm-core/pull/5440 (Fsa/new version management) was merged in latest release, is there a way we can mitigate active versions growing with this new version management?
Thanks in advance.chrmelchior
03/12/2023, 3:43 PMClosing intermediate version
in the log.
The easiest way to get into this situation is if you query for an object on startup and then store it in a static variable. Then you will pin the database to that version preventing it from releasing all the intermediate versions. If you have objects that are long-lived you can use copyFromRealm
. Then the data is copied into memory and the database is free to progress from there.
I hope that helps?Paolo Rotolo
03/12/2023, 4:03 PMrealm.query<Data>("id = $id")
.asFlow()
.map { it.list.firstOrNull()?.asMyObject }
copyToRealm
after a write, but still the number increases
realm.write {
copyToRealm(data, updatePolicy = UpdatePolicy.ALL )
}.copyFromRealm()
chrmelchior
03/12/2023, 4:10 PMcopyFromRealm
because the Realm itself is moved to that version.
Anecdotically I have often seen 50+ versions before the GC kicks inPaolo Rotolo
03/12/2023, 4:12 PMchrmelchior
03/12/2023, 4:12 PMPaolo Rotolo
03/12/2023, 4:14 PMchrmelchior
03/12/2023, 4:14 PMrealm.query<Data>("id = $id")
.asFlow()
.map { it.list.firstOrNull()?.asMyObject }
Should be fine, it will send a version down the flow and then that version will be removed by the GC once the map
operation is done with itPaolo Rotolo
03/12/2023, 4:20 PMrealm.query<Data>("id = $id")
.asFlow()
.map { it.list.firstOrNull() }
Will it cause version pinning, so I should be doing this instead?
realm.query<Data>("id = $id")
.asFlow()
.map { it.list.copyFromRealm().firstOrNull() }
chrmelchior
03/13/2023, 11:02 AM