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

Callbacks registered in a context are never released (until the Context is disposed of) #29

Open
augustoroman opened this issue May 15, 2018 · 1 comment

Comments

@augustoroman
Copy link
Owner

Each context keeps a map of registered callbacks. When the registered callback is called from V8, this map allows the go side of things to actually call the correct callback.

Unfortunately, the code currently has no way of knowing when a particular callback is no longer accessible from the JS, so there's no way to clean up the callback registrations.

This means that registering many callbacks is a source of memory leaks.

A potential solution is to explicitly un-register a callback (deleting it from the context map) and, if a callback comes in for an unregistered entry we just consider it a failure (i.e. throw an error in JS).

@jeromegn
Copy link
Collaborator

This is "best effort" according to the v8 docs, but we could maybe use SetWeak on the persistent value: https://v8.paulfryzel.com/docs/master/classv8_1_1_persistent_base.html#aebb8a2c97e219102f613ff3749c956f6

I'm not entirely sure how we'd be able to determine which value to clear in go though. Maybe there's a way to pass data somehow.

Just to be sure: this will leak the size of callbackInfo in go (a func and a string), but it won't leak within v8, right?

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

2 participants