Skip to content

Commit c4b78ae

Browse files
committed
chore: Memory leaks
1 parent 9090be3 commit c4b78ae

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/Document.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,15 @@ export class Document extends HasProvider implements IFile, HasMimeType {
160160
}
161161
public get tfile(): TFile | null {
162162
if (!this._tfile) {
163-
this._tfile = this._parent.getTFile(this);
163+
this._tfile = this.getTFile();
164164
}
165165
return this._tfile;
166166
}
167167

168+
getTFile(): TFile | null {
169+
return this._parent.getTFile(this);
170+
}
171+
168172
public get ytext(): Y.Text {
169173
return this.ydoc.getText("contents");
170174
}
@@ -463,6 +467,7 @@ export class Document extends HasProvider implements IFile, HasMimeType {
463467
this.whenSyncedPromise = null as any;
464468
this.readyPromise?.destroy();
465469
this.readyPromise = null as any;
470+
this._parent = null as any;
466471
}
467472

468473
public async read(): Promise<string> {

src/LiveViews.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export class LoggedOutView implements S3View {
116116

117117
destroy() {
118118
this.release();
119+
this.banner?.destroy();
119120
this.banner = undefined;
120121
this.view = null as any;
121122
}

src/markdownView/InvalidLinkExtension.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "@codemirror/view";
99
import { WidgetType } from "@codemirror/view";
1010
import {
11-
LiveView,
11+
LiveView,
1212
LiveViewManager,
1313
ConnectionManagerStateField,
1414
} from "../LiveViews";
@@ -87,11 +87,10 @@ export class InvalidLinkPluginValue {
8787

8888
if (this.view.document) {
8989
this.view.document.whenSynced().then(() => {
90-
if (this.connectionManager && this.app && this.view?.document?.tfile) {
91-
this.connectionManager.onMeta(this.view.document.tfile, this.cb);
92-
const fileCache = this.app.metadataCache.getFileCache(
93-
this.view.document.tfile,
94-
);
90+
const tfile = this.view?.document?.getTFile();
91+
if (this.connectionManager && this.app && tfile) {
92+
this.connectionManager.onMeta(tfile, this.cb);
93+
const fileCache = this.app.metadataCache.getFileCache(tfile);
9594
if (fileCache) {
9695
this.updateFromMetadata(fileCache);
9796
this.editor.dispatch({

src/observable/ObservableMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class ObservableMap<K, V> extends Observable<ObservableMap<K, V>> {
8888
}
8989
const derivedMap = new DerivedMap<K, V>(this, predicate);
9090
this._derivedMaps.set(predicate, derivedMap);
91+
this.unsubscribes.push(derivedMap.destroy);
9192
return derivedMap;
9293
}
9394
}

src/ui/Banner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class Banner {
6363
if (bannerBox) {
6464
bannerBox.replaceChildren();
6565
}
66+
this.onClick = async () => true;
6667
return true;
6768
}
6869
}

0 commit comments

Comments
 (0)