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

Reuse existing JavaScript proxy objects instead of creating duplicates #70

Open
mmomtchev opened this issue Sep 27, 2024 · 0 comments
Open

Comments

@mmomtchev
Copy link
Owner

Currently the following pattern:

class Object;

Object *fn() {
  static Object o;
  return &o;
}

will always create a new JavaScript proxy object for each invocation. Not only this is wasteful, but also operations such as

fn() === fn()

would not have the expected result.

This problem exists in most languages supported by SWIG.

It can be solved by storing weak references to all returned objects in a hash table indexed by the pointer address.

However there are practical problems with handling the destruction of these objects in JavaScript - namely the V8 delayed destruction which cancels the weak references without immediately destroying the objects.

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

1 participant