Skip to content

fix: Fix some memory leaks - #10217

Merged
gonfunko merged 1 commit into
mainfrom
sieve
Jul 31, 2026
Merged

gonfunko merged 1 commit into
mainfrom
sieve

Conversation

@gonfunko

Copy link
Copy Markdown
Contributor

The basics

The details

Proposed Changes

This PR fixes some memory leaks. These were largely related to (a) not unregistering tooltip listeners or clearing the .tooltip property on DOM elements, which various Blockly-related classes were stuffed into, sometimes creating cycles and (b) missing clearing an element in the block flyout inflater.

Reason for Changes

RAM is expensive, and cleaning up your own mess is nice.

@gonfunko
gonfunko requested a review from a team as a code owner July 31, 2026 20:23
@gonfunko
gonfunko requested a review from lizschwab July 31, 2026 20:23
@github-actions github-actions Bot added the PR: fix Fixes a bug label Jul 31, 2026
@gonfunko gonfunko mentioned this pull request Jul 31, 2026

@lizschwab lizschwab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of questions. I don't think either is enough to hold back an approval, but take a look.

Tooltip.unbindMouseEvents(clickTarget);
delete (clickTarget as any).tooltip;
}
this.tooltip = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this sets the tooltip to null but the others set it to an empty string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the tooltip field is nullable here, but not on the others. Either way will prevent cycles or leaks – I'd prefer to null it out everywhere, but don't want to change the API.

dom.removeNode(this.svgRoot);
if (this.svgRoot) {
tooltip.unbindMouseEvents(this.svgRoot);
delete (this.svgRoot as any).tooltip;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of these delete (foo as any).tooltip, is it possible to throw? Would they ever be undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icon and Field, which can be headless, both check for non-nullness of the thing on which .tooltip lives. BlockSvg doesn't, but it also will always have an SVG path. The delete keyword is documented as being a no-op if the property being deleted doesn't exist, so this should all be safe.

@gonfunko
gonfunko merged commit 761f15d into main Jul 31, 2026
10 checks passed
@gonfunko
gonfunko deleted the sieve branch July 31, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants