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
@@ -440,16 +440,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
.store(in: &cancellables) .store(in: &cancellables)
Task { [weak self] in Task { [weak self] in
guard let self else { // Don't guard let self here, otherwise the for await will strongify the self reference creating a strong reference cycle.
return
}
// 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. // 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 { for await _ in roomInfoSubscription.receive(on: DispatchQueue.main).values {
guard !Task.isCancelled else { guard !Task.isCancelled else {
return return
} }
await updatePinnedEventIDs() await self?.updatePinnedEventIDs()
} }
} }
.store(in: &cancellables) .store(in: &cancellables)