-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(core): clear State map on exit #14423
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
base: dev
Are you sure you want to change the base?
Conversation
Package Changes Through 69e00dbNo changes. Add a change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
| for (_, webview) in self.manager.webviews() { | ||
| webview.resources_table().clear(); | ||
| } | ||
| unsafe { self.manager.state.clear() }; |
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.
This is probably not what we want, someone could still be holding onto one of the pointers returned from the state manager while calling this (unless we change the states to Arc/Rc)
I honestly feel like the entire state system is a bit redundant considering it just stores things globally which you can already do with static except for maybe multiple tauri instances
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 exactly. I don't know how much that matters on app shutdown though.
But I only opened this PR to learn something, not to actually merge this.
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.
I honestly feel like the entire state system is a bit redundant considering it just stores things globally which you can already do with static except for maybe multiple tauri instances
You mean something like this?
static STATE: OnceLock<std::sync::Mutex<State>> = OnceLock::new();
pub fn get_state() -> &'static std::sync::Mutex<State> {
STATE.get_or_init(|| {
std::sync::Mutex::new(State::new())
})
}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 something like that
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.
This is probably not what we want, since someone could still be holding onto one of the pointers returned from the state manager while calling this (unless we change the states to Arc/Rc).
The state has the same lifetime as the manager, which to some extent mitigates this issue, because you shouldn’t be using tauri’s API after exit.
Nonetheless, I think this might be a breaking change, as it alters the previous behavior.
(Oh, I see — the cyclic references caused the memory leak. Then I think this is reasonable, as long as we note this in the Manager::state documentation.)
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.
OnceLock appears to also not drop its contents at the end:
Static items have the static lifetime, which outlives all other lifetimes in a Rust program. Static items do not call drop at the end of the program.
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.
The state has the same lifetime as the manager, which to some extent mitigates this issue, because you shouldn’t be using tauri’s API after exit.
Yeah.. but from looking at how we use them in RunEvent::Exit, we can't change this until v3 at least
Static items have the static lifetime, which outlives all other lifetimes in a Rust program. Static items do not call drop at the end of the program.
Yeah, you'll need to do it manually as well...
related to #14420
This is very fucked up and shouldn't be done right?