Fix for a memory leak (#3143)

This commit is contained in:
Mauro 2024-08-08 19:04:02 +02:00 committed by GitHub
parent ed7d3b0b13
commit b84c436551
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -440,16 +440,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
.store(in: &cancellables)
Task { [weak self] in
guard let self else {
return
}
// Don't guard let self here, otherwise the for await will strongify the self reference creating a strong reference cycle.
// If the subscription has sent a value before the Task has started it might be lost, so before entering the loop we always do an update.
await updatePinnedEventIDs()
await self?.updatePinnedEventIDs()
for await _ in roomInfoSubscription.receive(on: DispatchQueue.main).values {
guard !Task.isCancelled else {
return
}
await updatePinnedEventIDs()
await self?.updatePinnedEventIDs()
}
}
.store(in: &cancellables)