diff --git a/.changes/cleanup-resource-table.md b/.changes/cleanup-resource-table.md new file mode 100644 index 000000000..07396fe65 --- /dev/null +++ b/.changes/cleanup-resource-table.md @@ -0,0 +1,5 @@ +--- +tauri: patch:bug +--- + +Fix resource tables not cleaned up on exit which causes tray icon inside resource tables not cleaned up on exit diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 8765c3a0e..cf59973c2 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -754,6 +754,13 @@ macro_rules! shared_app_impl { pub fn cleanup_before_exit(&self) { #[cfg(all(desktop, feature = "tray-icon"))] self.manager.tray.icons.lock().unwrap().clear(); + self.manager.resources_table().clear(); + for (_, window) in self.manager.windows().iter() { + window.resources_table().clear(); + } + for (_, webview) in self.manager.webviews().iter() { + webview.resources_table().clear(); + } } } @@ -1700,8 +1707,7 @@ tauri::Builder::default() if let Some(tooltip) = &tray_config.tooltip { tray = tray.tooltip(tooltip); } - let tray = tray.build(handle)?; - app.manager.tray.icons.lock().unwrap().push(tray); + tray.build(handle)?; } } diff --git a/core/tauri/src/resources/mod.rs b/core/tauri/src/resources/mod.rs index fcf8982e3..2c7fa0182 100644 --- a/core/tauri/src/resources/mod.rs +++ b/core/tauri/src/resources/mod.rs @@ -209,4 +209,10 @@ impl ResourceTable { .ok_or_else(|| crate::Error::BadResourceId(rid)) .map(|resource| resource.close()) } + + /// Removes and frees all resources stored. Note that the + /// resource's `close()` method is *not* called. + pub(crate) fn clear(&mut self) { + self.index.clear() + } }