Skip to content

Commit

Permalink
Fix for a memory leak (#3143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 authored Aug 8, 2024
1 parent ed7d3b0 commit b84c436
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b84c436

Please sign in to comment.