Skip to content

Commit

Permalink
Fix VPN view model memory leak (#2570)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/414235014887631/1206803287661273/f
Tech Design URL:
CC: @graeme

Description:

This PR fixes a view model memory leak in the VPN code.
  • Loading branch information
samsymons authored Mar 10, 2024
1 parent 92ee914 commit 072cbaf
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions DuckDuckGo/NetworkProtectionStatusViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ final class NetworkProtectionStatusViewModel: ObservableObject {
private let serverInfoObserver: ConnectionServerInfoObserver
private let errorObserver: ConnectionErrorObserver
private var cancellables: Set<AnyCancellable> = []
private var delayedToggleReenableCancellable: Cancellable?

// MARK: Error

Expand Down Expand Up @@ -158,12 +157,11 @@ final class NetworkProtectionStatusViewModel: ObservableObject {
// Each event cancels the previous delayed publisher
$shouldDisableToggle
.filter { $0 }
.map {
Just(!$0)
.delay(for: 2.0, scheduler: DispatchQueue.main)
.assign(to: \.shouldDisableToggle, onWeaklyHeld: self)
.map { _ -> AnyPublisher<Bool, Never> in
Just(false).delay(for: 2.0, scheduler: DispatchQueue.main).eraseToAnyPublisher()
}
.assign(to: \.delayedToggleReenableCancellable, onWeaklyHeld: self)
.switchToLatest()
.assign(to: \.shouldDisableToggle, onWeaklyHeld: self)
.store(in: &cancellables)
}

Expand Down

0 comments on commit 072cbaf

Please sign in to comment.