-
Notifications
You must be signed in to change notification settings - Fork 391
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
Finalizer not invoked automatically with sharedworkers #673
Comments
I did manage to hack together a version with Following this: whatwg/html#1766 (comment)
Bonus is that it should also be more performant than weakRef for ongoing tasks. |
Oh interesting. That might be a corner-case (i.e. working as intended) of the So if you want to be sure that the finalizer gets called, your approach with |
WeakRefs should work (in theory) when closing the tab according to some blog posts online, but I didn't get around to test yet outside the Comlink setup. Unfortunately beforeunload is not reliable enough from our testing. Locks works great though. For us, running a cleanup after tabs is crucial for memory management. The shared worker can be running for months on end with variable number of tabs. Anyways, we're happy now, but there could be some merit in incorporating a solution into the library. So many people are asking the question, yet there's no straightforward solution. |
It doesn't seem like finalizer gets invoked for sharedworkers. I have the following worker, and the finalizer never gets invoked automatically.
It does work when I invoke it manually on beforeunload:
I also tried to wrap the port in weakRef myself before passing it to
Comlink.expose
, but no luck either. Was following this post: https://brightinventions.pl/blog/sharing-websocket-connections-between-browser-tabs-and-windows/Environment:
MacOS 15
Chrome Version 130.0.6723.117 (Official Build) (arm64)
The text was updated successfully, but these errors were encountered: