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

Question regarding leaking ExternalReferences when making JsRuntime #386

Closed
nyannyacha opened this issue Dec 13, 2023 · 3 comments
Closed

Comments

@nyannyacha
Copy link

nyannyacha commented Dec 13, 2023

Hi!
I'm sorry if this was a stupid question.

While I investigating the runtime that was built on Deno code base (actually edge-runtime of supabase 😁), I observed a memory leak on JsRuntime (and precisely the part of leaking external references).

But I don't understand why ExternalReferences should be leaked on all paths.

let refs = bindings::external_references(&op_ctxs, &additional_references);
// V8 takes ownership of external_references.
let refs: &'static v8::ExternalReferences = Box::leak(Box::new(refs));

I knew that ownership of external references must be maintained while creating a snapshot 1 2.
But I never heard that restriction also applied when creating a normal isolate instance 🧐

Is there some background that I didn't know about on this?

Before I submitted this issue, I made a fork that adjusts the leak behavior, and there were no leaks regarding external references as expected.

There's the same discussion about this on the Deno repository, but that was open for a long time and it seems no one has a clear answer. 🙄 (denoland/deno#18414)

Any thoughts about this?

@mmastrac
Copy link
Contributor

I'm about to rework a lot of the runtime/realm setup code over the next few weeks, so I can take a look at this when I'm in there.

@bartlomieju
Copy link
Member

I believe this is now fixed in #509

@nyannyacha
Copy link
Author

@bartlomieju 🙄 But... If I'm looking at it right…it looks like you leaked the lifetime again...? Isn't it?
Am I looking at it wrong? I'm confused 😵‍💫

#499
https://github.com/denoland/deno_core/blob/main/core/runtime/bindings.rs#L92-L94
https://github.com/denoland/deno_core/blob/main/core/runtime/setup.rs#L115-L129

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