Skip to content

Commit

Permalink
Fix memory leak in reactive gesture recognizer
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah committed Apr 27, 2023
1 parent ddf7654 commit ca0c69a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Calendr/Extensions/NSGestureRecognizer+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension Reactive where Base: NSView {

private func gesture<T: NSGestureRecognizer>(_ configure: @escaping (T) -> Void) -> Observable<Void> {

Observable.create { observer in
Observable.create { [weak base] observer in

let target = GestureProxy(observer)

Expand All @@ -43,11 +43,11 @@ extension Reactive where Base: NSView {

configure(click)

base.addGestureRecognizer(click)
base?.addGestureRecognizer(click)

return Disposables.create {
_ = target // keep a strong reference
base.removeGestureRecognizer(click)
base?.removeGestureRecognizer(click)
}
}
.share(replay: 1)
Expand Down

0 comments on commit ca0c69a

Please sign in to comment.