-
-
Notifications
You must be signed in to change notification settings - Fork 93
fix: add dispose() methods to prevent VRAM/GTT memory leaks #701
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
Open
bechampion
wants to merge
1
commit into
ErikReider:main
Choose a base branch
from
bechampion:fix/vram-gtt-memory-leak
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,22 @@ namespace SwayNotificationCenter { | |
|
|
||
| private Notification () {} | ||
|
|
||
| public override void dispose () { | ||
| // Clear all image resources to release VRAM/GPU memory | ||
| img.clear (); | ||
| img_app_icon.clear (); | ||
| body_image.set_paintable (null); | ||
|
|
||
| // Remove any pending timeout | ||
| remove_noti_timeout (); | ||
|
|
||
| // Clear gesture/controller references | ||
| gesture = null; | ||
| motion_controller = null; | ||
|
|
||
| base.dispose (); | ||
| } | ||
|
|
||
| /** Show a non-timed notification */ | ||
| public Notification.regular (NotifyParams param, | ||
| NotificationType notification_type) { | ||
|
|
@@ -309,7 +325,8 @@ namespace SwayNotificationCenter { | |
|
|
||
| this.body.set_lines (this.number_of_body_lines); | ||
|
|
||
| // Reset state | ||
| // Reset state - clear paintable to release GPU memory | ||
| body_image.set_paintable (null); | ||
| body_image.hide (); | ||
|
|
||
| // Removes all image tags and adds them to an array | ||
|
|
@@ -344,8 +361,23 @@ namespace SwayNotificationCenter { | |
| string img = Functions.uri_to_path (img_paths[0]); | ||
| File file = File.new_for_path (img); | ||
| if (img.length > 0 && file.query_exists ()) { | ||
| Gdk.Texture texture = Gdk.Texture.from_file (file); | ||
| body_image.set_paintable (texture); | ||
| // Clear previous body image to release GPU memory | ||
| body_image.set_paintable (null); | ||
|
bechampion marked this conversation as resolved.
|
||
| // Load image scaled to display size to save GPU memory | ||
| // Full-res images (e.g., 2560x1440 screenshots) waste VRAM | ||
| try { | ||
| Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file_at_scale ( | ||
| img, | ||
| notification_body_image_width * get_scale_factor (), | ||
| notification_body_image_height * get_scale_factor (), | ||
| true); // preserve aspect ratio | ||
| Gdk.Texture texture = Gdk.Texture.for_pixbuf (pixbuf); | ||
| body_image.set_paintable (texture); | ||
| } catch (Error e) { | ||
| // Fallback to full-size load if scaling fails | ||
| Gdk.Texture texture = Gdk.Texture.from_file (file); | ||
| body_image.set_paintable (texture); | ||
| } | ||
| body_image.set_can_shrink (true); | ||
| body_image.set_content_fit (Gtk.ContentFit.SCALE_DOWN); | ||
| body_image.width_request = notification_body_image_width; | ||
|
|
@@ -485,7 +517,8 @@ namespace SwayNotificationCenter { | |
| } | ||
|
|
||
| private void set_style_urgency () { | ||
| // Reset state | ||
| // Reset state - clear paintable to release GPU memory | ||
| body_image.set_paintable (null); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the paintable here? |
||
| base_box.remove_css_class ("low"); | ||
| base_box.remove_css_class ("normal"); | ||
| base_box.remove_css_class ("critical"); | ||
|
|
@@ -505,7 +538,8 @@ namespace SwayNotificationCenter { | |
| } | ||
|
|
||
| private void set_inline_reply () { | ||
| // Reset state | ||
| // Reset state - clear paintable to release GPU memory | ||
| body_image.set_paintable (null); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| inline_reply_box.hide (); | ||
| // Only show inline replies in popup notifications if the compositor | ||
| // supports ON_DEMAND layer shell keyboard interactivity | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree. This was a temporary hack to fix keyboard input.
This was needed though to know which output the ControlCenter was opened on as the underlying wl_surface doesn't get destroyed / the wl_surface::leave signal isn't called when unmapped. Without a wl_surface::leave, the ::enter signal is only called once for each output, which makes tracking which monitor the ControlCenter is open on impossible.
So please remove this change as it should be in a separate PR