Skip to content

fix(turtles): Clear intervals when removing turtles to prevent memory…#5106

Merged
walterbender merged 1 commit intosugarlabs:masterfrom
WillyEverGreen:fix/meter-actions-interval-cleanup
Jan 18, 2026
Merged

fix(turtles): Clear intervals when removing turtles to prevent memory…#5106
walterbender merged 1 commit intosugarlabs:masterfrom
WillyEverGreen:fix/meter-actions-interval-cleanup

Conversation

@WillyEverGreen
Copy link
Copy Markdown
Contributor

Description

Fixes a memory leak where intervals created by MeterActions.onEveryBeatDo() were not cleared when turtles were removed.

Problem

When a turtle with an active "On Every Beat Do" interval is deleted, the setInterval continues running as a "zombie" interval, causing:

  • Memory leaks in long-running sessions
  • Potential performance degradation
  • Unexpected behavior from orphaned interval callbacks

Solution

Added interval cleanup logic to [removeTurtle()] in [js/turtles.js]:

  • Check if the turtle has an active interval property
  • Clear it with clearInterval() before removal
  • Set turtle.interval = undefined for clean state

Testing

  • npm run lint
  • npm test
  • Manual verification: Create turtle with "On Every Beat Do" block, delete turtle, confirm interval is cleared

Impact

  • Prevents memory leaks during normal usage
  • Improves stability in extended sessions
  • No breaking changes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

✅ All Jest tests passed! This PR is ready to merge.

@walterbender walterbender merged commit 2f41508 into sugarlabs:master Jan 18, 2026
5 checks passed
021nirav-blip pushed a commit to 021nirav-blip/musicblocks that referenced this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants