Skip to content

Reference leak when doing Object.freeze #35

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

Open
Matthiee opened this issue Dec 12, 2022 · 1 comment
Open

Reference leak when doing Object.freeze #35

Matthiee opened this issue Dec 12, 2022 · 1 comment

Comments

@Matthiee
Copy link

Matthiee commented Dec 12, 2022

When I dispose the QuickJS engine I get a reference leak after doing a Object.freeze.

reference leak:
    ADDR	REF	TYPE	PROP
  986107159	1	_JSFunction	function () { ...
#0      new JSError
package:flutter_qjs/src/object.dart:93
#1      FlutterQjs.close
package:flutter_qjs/src/engine.dart:136
#2      main.<anonymous closure>

If I don't do the Object.freeze it all works fine.

To reproduce run this test code:

test('ref leak', () async {
    final qjs = FlutterQjs(timeout: 1000);

    int counter = 0;

    void click() => counter++;

    final myObj = {'click': click};

    final JSInvokable setToGlobal = await qjs.evaluate(
      '(name, obj) => { this[name] = obj; }',
    );

    setToGlobal.invoke(['myObj', myObj]);

    setToGlobal.free();

    // comment the following line and it will work.
    await qjs.evaluate('Object.freeze(myObj);');
    await qjs.evaluate('myObj.click();');

    expect(counter, 1);

    expect(
      () => qjs.close(),
      returnsNormally,
      reason:
          'There should be no reference leak when freezing an object in QuickJS',
    );
  });
@evan-mcgeek
Copy link

@ekibun any updates on this?

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