Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak fixed #118

Merged
merged 1 commit into from
May 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ final class TabCollectionViewModel: NSObject {
updateSelectedTabViewModel()
}
}
@Published private(set) var selectedTabViewModel: TabViewModel?
@Published private(set) var selectedTabViewModel: TabViewModel? {
didSet {
previouslySelectedTabViewModel = oldValue
}
}
private weak var previouslySelectedTabViewModel: TabViewModel?

@Published private(set) var canInsertLastRemovedTab: Bool = false
Expand All @@ -61,7 +65,6 @@ final class TabCollectionViewModel: NSObject {

subscribeToTabs()
subscribeToLastRemovedTab()
subscribeToSelectedTabViewModel()

if tabCollection.tabs.isEmpty {
appendNewTab()
Expand Down Expand Up @@ -318,14 +321,6 @@ final class TabCollectionViewModel: NSObject {
} .store(in: &cancellables)
}

private func subscribeToSelectedTabViewModel() {
$selectedTabViewModel
.scan((nil, nil)) { return ($0.1, $1) }
.sink { [weak self] (previouslySelectedTabViewModel, _) in
self?.previouslySelectedTabViewModel = previouslySelectedTabViewModel
}.store(in: &cancellables)
}

private func removeTabViewModels(_ removed: Set<Tab>) {
for tab in removed {
tabViewModels[tab] = nil
Expand Down