aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_content_view/conversation_item_skeleton.vala
diff options
context:
space:
mode:
authorChristopher Vollick <0@psycoti.ca>2023-09-14 15:12:58 -0400
committerMarvin W <git@larma.de>2024-04-28 21:36:27 +0200
commitd473efcbfe3603fac62594bd9d8fee8b23ffcbe5 (patch)
treeec7d09a8ac92b3ab434b383ab02215aa2632055b /main/src/ui/conversation_content_view/conversation_item_skeleton.vala
parentba83a4ba3d6886b711278b8804566dcbe8ad7621 (diff)
downloaddino-d473efcbfe3603fac62594bd9d8fee8b23ffcbe5.tar.gz
dino-d473efcbfe3603fac62594bd9d8fee8b23ffcbe5.zip
Add WeakTimeout Pattern to Prevent Leaks
While doing testing I noticed that skeletons were being leaked, and eventually tracked it down to the timer that updates the time label closing over "this" and then keeping the reference alive, potentially for 24 hours. I noticed a few other places in the code doing some version of this, and one of them had the "static and weak pointer" approach, which I pulled out into a util class. Now, we still have to make sure we're passing it a static method instead of a lambda, as that would also close over "this" and render the whole thing useless, but at least most of the annoying parts live in the util class now. Also the call_widget version was doing a weird thing where it was removing itself, but then returning "true"? I'm not sure what that accomplishes, because returning "false" means to not run this again. So I think my new version is the same in practice, but simpler... There are other timeouts in the code that I briefly looked over, but all of them seemed to be relatively short hard-coded durations, so I left them alone. But if any of them are long-lived, it's possible they could also benefit from this class in the future. Closes #1480 Co-Authored-By: Marvin W <git@larma.de>
Diffstat (limited to 'main/src/ui/conversation_content_view/conversation_item_skeleton.vala')
-rw-r--r--main/src/ui/conversation_content_view/conversation_item_skeleton.vala10
1 files changed, 5 insertions, 5 deletions
diff --git a/main/src/ui/conversation_content_view/conversation_item_skeleton.vala b/main/src/ui/conversation_content_view/conversation_item_skeleton.vala
index 5d86f6c7..3b818b44 100644
--- a/main/src/ui/conversation_content_view/conversation_item_skeleton.vala
+++ b/main/src/ui/conversation_content_view/conversation_item_skeleton.vala
@@ -173,14 +173,14 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface,
set_widget(widget, Plugins.WidgetType.GTK4, 3);
}
+ private void on_time_update_timeout() {
+ if (main_grid.parent != null) update_time();
+ }
+
private void update_time() {
time_label.label = get_relative_time(item.time.to_local()).to_string();
- time_update_timeout = Timeout.add_seconds((int) get_next_time_change(item.time), () => {
- if (this.main_grid.parent == null) return false;
- update_time();
- return false;
- });
+ time_update_timeout = Dino.WeakTimeout.add_seconds_once((int) get_next_time_change(item.time), this, on_time_update_timeout);
}
private void update_name_label() {