diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf3a8bc8..709cedf25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ 4.8.6 (unreleased) -------------------------- +### Fixes + +- Fix a trivial memory leak in the line ending menu (thanks to Yoshimasa Niwa). + 4.8.5 (653) diff --git a/CotEditor/Sources/OptionalMenu.swift b/CotEditor/Sources/OptionalMenu.swift index c19a7510e..7c1a6980c 100644 --- a/CotEditor/Sources/OptionalMenu.swift +++ b/CotEditor/Sources/OptionalMenu.swift @@ -8,7 +8,7 @@ // // --------------------------------------------------------------------------- // -// © 2022-2023 1024jp +// © 2022-2024 1024jp // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -59,9 +59,11 @@ final class OptionalMenu: NSMenu, NSMenuDelegate { func menuWillOpen(_ menu: NSMenu) { self.update() // UI validation is performed here - self.validateKeyEvent(force: true) + self.validateKeyEvent(forcibly: true) - let timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(validateKeyEvent), userInfo: nil, repeats: true) + let timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] _ in + self?.validateKeyEvent() + } RunLoop.current.add(timer, forMode: .eventTracking) self.trackingTimer = timer } @@ -78,12 +80,12 @@ final class OptionalMenu: NSMenu, NSMenuDelegate { /// Checks the state of the modifier key press and update the item visibility. /// - /// - Parameter force: Whether forcing to update the item visibility. - @objc private func validateKeyEvent(force: Bool = false) { + /// - Parameter forcibly: Whether forcing to update the item visibility. + @objc private func validateKeyEvent(forcibly: Bool = false) { let shows = NSEvent.modifierFlags.contains(.option) - guard force || shows != self.isShowingOptionalItems else { return } + guard forcibly || shows != self.isShowingOptionalItems else { return } self.updateOptionalItems(shows: shows) }