Skip to content

Use WeakRefs for JS<->Wasm memory debugging #11436

@RReverser

Description

@RReverser

Now that WeakRefs are getting available in both Chromium in Firefox, it might be tempting to look at them in context of JS <-> Wasm interactions, particularly, via Embind and WebIDL.

While WeakRefs are not a reliable mechanism to use as a replacement for upcoming Wasm GC integration, and are not available on all platforms yet, I think we could at least use them to help users with debugging memory leaks.

As a particular example, I'd imagine that when code is compiled with ASSERTIONS and WeakRef support is detected in the JS runtime, Emscripten could attach finalisation handlers to Embind / WebIDL objects and say "hey, looks like you forgot to call .destroy() / .delete() on this value at this line of code" when a leak is detected.

This should help to detect and solve a fairly common source of memory leaks in JS<->Wasm code much faster IMO. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions