diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt index a9be28e6ae..19e46607ef 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt @@ -311,6 +311,8 @@ class RoomListPresenter @Inject constructor( private fun CoroutineScope.clearCacheOfRoom(roomId: RoomId) = launch { client.getRoom(roomId)?.use { room -> + // Ideally we wouldn't have a live timeline at this point, but right now we instantiate one when retrieving the room + room.liveTimeline.close() room.clearEventCacheStorage() } } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustRoomFactory.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustRoomFactory.kt index 2bcd15c142..a65112fca9 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustRoomFactory.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustRoomFactory.kt @@ -81,6 +81,10 @@ class RustRoomFactory( withContext(NonCancellable + dispatcher) { mutex.withLock { Timber.d("Destroying room factory") + cache.snapshot().values.forEach { (listItem, innerRoom) -> + innerRoom.destroy() + listItem.destroy() + } cache.evictAll() isDestroyed = true }