Skip to content
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

Does the store get dropped when a component dismounts? #60

Open
rollo-b2c2 opened this issue Sep 10, 2023 · 2 comments
Open

Does the store get dropped when a component dismounts? #60

rollo-b2c2 opened this issue Sep 10, 2023 · 2 comments

Comments

@rollo-b2c2
Copy link

I was looking at the implementation of use store and I saw it used a threadlocal to do the global state.

If a component is dismounted, and it’s the only component using a certain store, does the store get dropped?

@0x32c2cac3info
Copy link

0x32c2cac3info commented Sep 19, 2023

I believe the store persists beyond the period when the component is dropped for two reasons. The first reason is found here in the second paragraph, when it says: ...

_"For types that do not need to be dropped, this can enable an even more efficient implementation that does not need to track any additional state."

The other reason I think it persists is because "Static items do not call [drop](https://doc.rust-lang.org/reference/destructors.html) at the end of the program.", but this isn't necessarily the end of the program, right?

If it looks like you'd be worried about losing a store without proper saving or cleanup, there's always ManuallyDrop provided a fork of the repo implements it on a newtype wrapping the thread local, or something.

@intendednull
Copy link
Owner

This is correct, stores live for the entire application lifetime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants