Skip to content

Commit 0361639

Browse files
committed
Fix memory leaks.
1 parent 8fe9c41 commit 0361639

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

devdocs-macos/DocumentationViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class DocumentationViewController:
3131
let ucc = webView.configuration.userContentController
3232
ucc.removeScriptMessageHandler(forName: "vcBus")
3333
ucc.removeAllUserScripts()
34+
webView.uiDelegate = nil
35+
3436
super.viewDidDisappear()
3537
}
3638

devdocs-macos/DocumentationWindowController.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class DocumentationWindowController: NSWindowController {
3636
private func observeViewerState() {
3737
guard let dvc = documentationViewController else { return }
3838
observations.insert(
39-
dvc.observe(\DocumentationViewController.viewerState) { (dvc, _) in
39+
dvc.observe(\DocumentationViewController.viewerState) { [weak self] (dvc, _) in
4040
if dvc.viewerState != .ready {
4141
return
4242
}
4343

4444
dvc.useNativeScrollbars(true)
4545

46-
guard let window = self.window else { return }
46+
guard let window = self?.window else { return }
4747
switch window.effectiveAppearance.name {
4848
case .aqua:
4949
dvc.useDarkMode(false)
@@ -59,26 +59,26 @@ class DocumentationWindowController: NSWindowController {
5959
private func observeDocumentTitle() {
6060
guard let dvc = documentationViewController else { return }
6161
observations.insert(
62-
dvc.observe(\DocumentationViewController.documentTitle) { (dvc, _) in
63-
self.window?.title = dvc.documentTitle ?? "DevDocs"
62+
dvc.observe(\DocumentationViewController.documentTitle) { [weak self] (dvc, _) in
63+
self?.window?.title = dvc.documentTitle ?? "DevDocs"
6464
}
6565
)
6666
}
6767

6868
private func observeDocumentURL() {
6969
guard let dvc = documentationViewController else { return }
7070
observations.insert(
71-
dvc.observe(\DocumentationViewController.documentURL) { (dvc, _) in
72-
self.documentation.url = dvc.documentURL
71+
dvc.observe(\DocumentationViewController.documentURL) { [weak self] (dvc, _) in
72+
self?.documentation.url = dvc.documentURL
7373
}
7474
)
7575
}
7676

7777
private func observeEffectiveAppearance() {
7878
guard let window = self.window else { return }
7979
observations.insert(
80-
window.observe(\NSWindow.effectiveAppearance) { (win, _) in
81-
guard let dvc = self.documentationViewController else {
80+
window.observe(\NSWindow.effectiveAppearance) { [weak self] (win, _) in
81+
guard let dvc = self?.documentationViewController else {
8282
return
8383
}
8484
switch window.effectiveAppearance.name {

0 commit comments

Comments
 (0)