Skip to content

Commit 69e00db

Browse files
committed
fix(core): clear State map on exit
1 parent dd70d21 commit 69e00db

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

crates/tauri/src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ macro_rules! shared_app_impl {
10371037
for (_, webview) in self.manager.webviews() {
10381038
webview.resources_table().clear();
10391039
}
1040+
unsafe { self.manager.state.clear() };
10401041
}
10411042

10421043
/// Gets the invoke key that must be referenced when using [`crate::webview::InvokeRequest`].

crates/tauri/src/state.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ impl StateManager {
149149
Some(*value)
150150
}
151151

152+
/// SAFETY: This will cause all references obtained through [Self::try_get] to dangle.
153+
/// This must only be called on app exit (in cleanup_before_exit).
154+
pub(crate) unsafe fn clear(&self) {
155+
let mut map = self.map.lock().unwrap();
156+
map.clear();
157+
}
158+
152159
/// Gets the state associated with the specified type.
153160
pub fn get<T: Send + Sync + 'static>(&self) -> State<'_, T> {
154161
self

0 commit comments

Comments
 (0)