Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory leak of graph view dispose(introduce by #4023) #4114

Merged
merged 1 commit into from
Jan 9, 2024
Merged
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
5 changes: 5 additions & 0 deletions packages/x6/src/graph/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class GraphView extends View {

private restore: () => void

/** Graph's `this.container` is from outer, should not dispose */
protected get disposeContainer(): boolean {
return false
}

protected get options() {
return this.graph.options
}
Expand Down
19 changes: 14 additions & 5 deletions packages/x6/src/view/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export abstract class View<A extends EventArgs = any> extends Basecoat<A> {
return 2
}

/** If need remove `this.container` DOM */
protected get disposeContainer() {
return true
}

constructor() {
super()
this.cid = Private.uniqueId()
Expand All @@ -39,8 +44,12 @@ export abstract class View<A extends EventArgs = any> extends Basecoat<A> {
this.removeEventListeners(document)
this.onRemove()
delete View.views[this.cid]
if (this.disposeContainer) {
this.unmount(elem)
}
} else {
this.unmount(elem)
}
this.unmount(elem)
return this
}

Expand Down Expand Up @@ -363,10 +372,10 @@ export abstract class View<A extends EventArgs = any> extends Basecoat<A> {
return View.normalizeEvent(evt)
}

// @View.dispose()
// dispose() {
// this.remove()
// }
@View.dispose()
dispose() {
this.remove()
}
}

export namespace View {
Expand Down
Loading