Skip to content

Commit

Permalink
fix: memory leak of graph view dispose(introduce by #4023) (#4114)
Browse files Browse the repository at this point in the history
Co-authored-by: cluezhang <[email protected]>
  • Loading branch information
cyrilluce and cluezhang authored Jan 9, 2024
1 parent c91a89f commit 8d0a850
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
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

0 comments on commit 8d0a850

Please sign in to comment.