eww
eww copied to clipboard
Potential fix for `for`-loop memory leak
Description
Some users, including me have been noticing a memory leak with included slowdowns when using the for
implementation, in my case for the Hyprland workspace widget provided here. There is also a related issue #794.
Looking at the related PR for this feature #350, I noticed the unsafe
calls for destroying the old widget, which seemed a bit odd. After trying to get a feel for the code and some negotiating with ChatGPT, I tried using the remove()
method that the GTK Container
class provides, which gets rid of the unsafe
code block.
After some usage of a custom build with this one-liner fix, the widget still works correctly, and I noticed that the memory leakage was gone.
EDIT:
Went ahead and removed an additional unsafe
call in the same file, which seems more appropriate now for removing each child widget using iter().for_each()
. Builds and works fine on my side.
I could be tapping in the dark here and missing something, if that is the case, please let me know!
Showcase
(Notice the MemB
)
This is the result after switching workspaces a couple of times after ten minutes of usage with the latest master branch.
This is with my added fix after 10 minutes and fast workspace switching.
Additional Notes
It would be cool if someone could double-check if this is really the fix. Other than that, this is just a single-line change.
Checklist
Please make sure you can check all the boxes that apply to this PR.
- [x] All widgets I've added are correctly documented.
- [x] I added my changes to CHANGELOG.md, if appropriate.
- [x] The documentation in the
docs/content/main
directory has been adjusted to reflect my changes. - [x] I used
cargo fmt
to automatically format all code before committing