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

proposal: syscall/js: remove Func.Release() #57435

garet90 opened this issue Dec 21, 2022 · 1 comment

proposal: syscall/js: remove Func.Release() #57435

garet90 opened this issue Dec 21, 2022 · 1 comment


Copy link

garet90 commented Dec 21, 2022

I propose we remove the js.Func.Release() method.


Currently, js.Func's are very prone to bugs. Developers have to manually call Release() on allocated js.Func's after they are sure there are no references. But, releasing funcs too early leads to errors when called again from the js side. On the other hand, never releasing funcs (although safer) results in memory leaks.

Unlike OS files, socket connections, and other manually freed resources, the lifetime of js.Func's are sometimes unclear, making them a good candidate for automatic collection.


In 2021, JavaScript added a new FinalizationRegistry class where a function may be called when an object is cleaned up by the garbage collector. Using this, we can clean up the func's resources when they are gc'd on the JavaScript side.


syscall/js is not covered by the go compatibility promise.

Alternatively, to not break current apps, Func.Release() can be turned into a no-op or work as usual alongside the new auto gc.

Most modern versions of major browsers support FinalizationRegistry, which is the current precedent for implementing changes to the wasm backend (see comment). In the event of incompatibility, the js.Func can be leaked, still allowing the program to run as normally as possible.

@gopherbot gopherbot added this to the Proposal milestone Dec 21, 2022
Copy link

CC @golang/js

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

No branches or pull requests

4 participants