Fix memory leak: action_system palette shortcut strings#94
Closed
Fix memory leak: action_system palette shortcut strings#94
Conversation
Each action's binding was formatted into a heap string with ActionRegistry.formatKey and handed to CommandPalette by reference. The palette stores Command structs verbatim — it never owns or frees the shortcut bytes — so the strings leaked at program exit (gpa reported one leak per registered action with a binding). Add a palette_shortcuts: ArrayList([]u8) field on Model that owns the formatted strings. Push each formatKey result into it, hand the slice to the palette by reference, and free everything in deinit. Verified: action_system now exits with zero gpa leak reports.
4 tasks
Owner
Author
|
Superseded by #95 — fixes the leak at the library level (CommandPalette now owns its command strings) instead of working around it in the example. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The leak fix from PR #93's branch landed too late — the merge happened before the second commit was pushed, so the leak fix never reached main. This PR re-applies it cleanly against main.
The leak
Each action with a binding had its shortcut string allocated via `ActionRegistry.formatKey(persistent, ...)` and passed to `CommandPalette` by reference. The palette stores `Command` structs verbatim — it never owns or frees the shortcut bytes — so on program exit the gpa reported one `memory address … leaked` entry per registered action with a binding.
Fix
Add a `palette_shortcuts: ArrayList([]u8)` field on the `Model` that owns the formatted strings:
This keeps the palette API simple (it stays a borrow-only consumer) while ensuring the example cleans up properly.
Test plan