Merged
Conversation
Previously CommandPalette stored Command structs verbatim — id, label, description, and shortcut were all borrowed slices. That forced every caller to keep the source strings alive for as long as the palette existed, and to free them itself on shutdown. Easy to get wrong (the action_system example leaked 8 shortcut strings on exit before the band-aid in PR #94). Library-side fix: addCommand and setCommands now clone every string into the palette's own allocator. deinit frees them. Callers can pass arena-allocated, formatted, or otherwise short-lived strings — no lifetime tracking required, like Table/List/Tree already do. Also adds: CommandPalette.setFromRegistry(*const ActionRegistry) A one-line integration that pulls every enabled action into the palette and formats bindings as shortcut hints. The action_system example collapses from a 17-line manual loop (and the PR #94 ownership workaround) down to a single line. Verified: action_system exits with zero gpa leak reports, even after repeated palette open/close cycles.
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
Better fix for the leak that PR #94 patched in user code: solve it in the library so no caller has to think about it.
The real problem
`CommandPalette` stored `Command` structs verbatim — `id`, `label`, `description`, and `shortcut` were all borrowed slices. That forced every caller to keep the source strings alive for as long as the palette existed, and to free them on shutdown. Easy to get wrong: the `action_system` example leaked 8 shortcut strings on exit until PR #94 added a manual ownership tracker on the user side.
That workaround should never have been the caller's job. Other widgets in the codebase (`Table`, `List`, `Tree`) all clone their content; `CommandPalette` was the odd one out.
Library changes
Example collapses
`action_system.zig` loses ~17 lines of manual `palette_cmds` building plus the ownership workaround, replaced by:
```zig
self.palette.setFromRegistry(&self.registry) catch {};
```
Test plan