-
Notifications
You must be signed in to change notification settings - Fork 5.9k
fix(state): delete key from recordsByKey on instance disposal #8252
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
Conversation
The State.dispose() function clears the entries Map but never deletes the key from recordsByKey. This causes unbounded memory growth as each disposed instance leaves an empty Map entry in recordsByKey forever. Add recordsByKey.delete(key) after entries.clear() to properly clean up the parent Map entry.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found related PRs addressing memory leak issues in disposal patterns, but they appear to focus on different areas: Potentially Related PRs:
These PRs address similar memory leak patterns in disposal/cleanup scenarios, but none appear to be direct duplicates of PR #8252. PR #8252 is specifically fixing the |
Duplicate AnalysisThe bot mentioned PRs #7032, #7914, and #7154 as potentially related. After investigation:
Verdict: Not a duplicate. This PR fixes a different memory leak pattern in a completely different file. The The other PRs focus on Bus subscription cleanup and permission cleanup - none touch |
|
/review |
|
lgtm |
|
@sauerdaniel thank you for finding these tiny details, they are hard to catch and great finds!!! very very much appreciated and I bet youll find more. please ping me if I miss ur prs because ur prs so far are better than most relating to mem/resource issues |
Summary
Fix memory leak in
State.dispose()where disposed instance keys remain in the parent Map forever.Fixes #4315
Relates to #3013
Problem
The
Statenamespace uses a two-level Map structure:recordsByKey: Map<string, Map<any, Entry>>- outer Map keyed by instanceWhen
State.dispose(key)is called:entries.clear()to empty the inner MaprecordsByKeyThis means every disposed instance leaves an empty
Map<any, Entry>inrecordsByKey, causing unbounded memory growth over the application lifetime.Solution
Add
recordsByKey.delete(key)afterentries.clear()to remove the outer Map entry entirely.Testing