Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

πŸ’» ⏰ Invalidate timer when view goes away to fix memory leaking #4884

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ class TimerViewController: NSViewController {

override func viewDidDisappear() {
super.viewDidDisappear()


viewModel.viewWillDisappear()

[projectAutocompleteDidResignObserver, tagsAutocompleteDidResignObserver]
.compactMap { $0 }
.forEach { NotificationCenter.default.removeObserver($0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final class TimerViewModel: NSObject {
var tagsDataSource = TagDataSource(items: TagStorage.shared.tags,
updateNotificationName: .TagStorageChangedNotification)

private var timer: Timer!
private var timer: Timer?

private var actionsUsedBeforeStart: Set<TimerEditActionType> = Set()

Expand All @@ -138,10 +138,14 @@ final class TimerViewModel: NSObject {

deinit {
cancelNotificationObservers()
timer.invalidate()
}

// MARK: - Public

func viewWillDisappear() {
timer?.invalidate()
timer = nil
}

func startStopAction() {
if timeEntry.isRunning() {
Expand Down