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: addresses memory leak when creating deriveds inside untrack #14443

Merged
merged 11 commits into from
Nov 26, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Nov 26, 2024

This was an odd memory leak that I've been tracking for weeks. I made the discovery today whilst looking into another issue that it was to do with untrack. Specifically, we only attach a derived to the parent effect when we're in a non tracking context – however, because nested deriveds only recorded their parent as effect, it meant that nested deriveds were incorrectly being added to the same effect after each run.

Rather than have the awkwardly deal with removing a derived from the parent each time, and know that deriveds can only be created where they are declared, we can instead just make the parent of a derived by that of an effect or another derived.

Copy link

changeset-bot bot commented Nov 26, 2024

🦋 Changeset detected

Latest commit: b16eb5f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-svelte-14443-svelte.vercel.app/

this is an automated message

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@14443

trueadm and others added 5 commits November 26, 2024 14:15
trueadm and others added 2 commits November 26, 2024 19:15
Co-authored-by: Rich Harris <rich.harris@vercel.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
@trueadm trueadm merged commit 45417a3 into main Nov 26, 2024
11 checks passed
@trueadm trueadm deleted the untrack-leak branch November 26, 2024 19:18
@github-actions github-actions bot mentioned this pull request Nov 26, 2024
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.

3 participants