Grzegorz Gajewski
08/25/2023, 11:30 AM1.7.0
and latest 1.10.2
. When I remove the code to collect the flow and run GC manually it drops (but only in 1.7.0
). What am I missing here? What are the strategies that we can use today to keep active realm versions low?
object Singleton {
val config = RealmConfiguration.create(schema = setOf(Item::class))
val realm = Realm.open(config)
}
class Item : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId()
var isComplete: Boolean = false
var summary: String = ""
var owner_id: String = ""
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val objectsCount = mutableStateOf(0L)
val versionsCount = mutableStateOf(realm.getNumberOfActiveVersions())
setContent {
RealmTestTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting(objectsCount.value.toString(), versionsCount.value.toString(), onClick = {
lifecycleScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
repeat(100) {
realm.write {
copyToRealm(Item().apply {
summary = "Do the laundry"
isComplete = false
})
}
delay(10)
versionsCount.value = realm.getNumberOfActiveVersions()
}
}
})
}
}
}
realm
.query<Item>()
.asFlow()
.onEach {
val summaries = it.list.map { it.summary }
objectsCount.value = summaries.count().toLong()
}
.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
.launchIn(lifecycleScope)
}
}
@Composable
fun Greeting(objectsCount: String, activeVersions: String, modifier: Modifier = Modifier, onClick: () -> Unit) {
Column() {
Text(
text = "Objects $objectsCount",
modifier = modifier
)
Text(
text = "Active versions $activeVersions",
modifier = modifier
)
Button(onClick = onClick) {
Text(text = "Insert 100 items")
}
}
}
Claus Rørbech
09/27/2023, 12:55 PM1.11.2-SNAPSHOT
.