Skip to content

Conversation

@FabianLars
Copy link
Member

related to #14420

This is very fucked up and shouldn't be done right?

@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Nov 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Package Changes Through 69e00db

No 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() };
Copy link
Contributor

@Legend-Master Legend-Master Nov 6, 2025

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

Copy link
Member Author

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.

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())
    })
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah something like that

Copy link
Contributor

@WSH032 WSH032 Nov 7, 2025

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.)

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.

Copy link
Contributor

@Legend-Master Legend-Master Nov 13, 2025

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

https://github.com/tauri-apps/plugins-workspace/blob/3019063ae1a3cda689cff6b8b786c8b770b0496b/plugins/single-instance/src/platform_impl/windows.rs#L111-L129

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📬Proposal

Development

Successfully merging this pull request may close these issues.

5 participants