Skip to content

Commit 761f15d

Browse files
authored
fix: Fix some memory leaks (#10217)
1 parent 5c87842 commit 761f15d

5 files changed

Lines changed: 17 additions & 2 deletions

File tree

packages/blockly/core/block.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ export class Block {
328328
*/
329329
dispose(healStack = false) {
330330
this.disposing = true;
331+
this.tooltip = '';
331332

332333
// Dispose of this change listener before unplugging.
333334
// Technically not necessary due to the event firing delay.

packages/blockly/core/block_flyout_inflater.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export class BlockFlyoutInflater implements IFlyoutInflater {
179179
const element = item.getElement();
180180
if (!(element instanceof BlockSvg)) return;
181181
this.removeListeners(element.id);
182+
this.permanentlyDisabledBlocks.delete(element);
182183
element.dispose(false, false);
183184
}
184185

packages/blockly/core/block_svg.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,8 @@ export class BlockSvg
899899
override dispose(healStack?: boolean, animate?: boolean) {
900900
this.disposing = true;
901901

902+
Tooltip.unbindMouseEvents(this.pathObject.svgPath);
903+
delete (this.pathObject.svgPath as any).tooltip;
902904
Tooltip.dispose();
903905
ContextMenu.hide();
904906

packages/blockly/core/field.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,13 @@ export abstract class Field<T = any>
661661
dom.removeNode(this.fieldGroup_);
662662
}
663663

664+
const clickTarget = this.getClickTarget_();
665+
if (clickTarget) {
666+
Tooltip.unbindMouseEvents(clickTarget);
667+
delete (clickTarget as any).tooltip;
668+
}
669+
this.tooltip = null;
670+
664671
this.disposed = true;
665672
}
666673

packages/blockly/core/icons/icon.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ export abstract class Icon implements IIcon, IContextMenu {
8181
}
8282

8383
dispose(): void {
84-
tooltip.unbindMouseEvents(this.svgRoot);
85-
dom.removeNode(this.svgRoot);
84+
if (this.svgRoot) {
85+
tooltip.unbindMouseEvents(this.svgRoot);
86+
delete (this.svgRoot as any).tooltip;
87+
dom.removeNode(this.svgRoot);
88+
}
89+
this.tooltip = '';
8690
}
8791

8892
getWeight(): number {

0 commit comments

Comments
 (0)