Skip to content

avoid capturing context in closures that don't need it #45603

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
mraleph opened this issue Apr 6, 2021 · 0 comments
Open

avoid capturing context in closures that don't need it #45603

mraleph opened this issue Apr 6, 2021 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-enhancement A request for a change that isn't a bug

Comments

@mraleph
Copy link
Member

mraleph commented Apr 6, 2021

In the code below () => 10 would have a parent context capturing v even though it does not need it. We could avoid linking closure context to parent context unless it really needs it.

foo(v) {
  return () {
    print(v);
    return () => 10;
  };
}

Related to flutter/flutter#79605

@mraleph mraleph added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-enhancement A request for a change that isn't a bug labels Apr 6, 2021
dart-bot pushed a commit that referenced this issue Sep 3, 2021
…d over

As a side-effect of making closures without captured variables have an
empty context, we not only avoid a memory leak, but also allow such
closures to be sent across [SendPort]s.

Issue #36983
Issue #45603

TEST=vm/dart{_2,}/isolates/closures_without_captured_variables_test

Change-Id: I5e8845203059ff625f7cff3f072d845b5e48ba36
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212297
Commit-Queue: Martin Kustermann <[email protected]>
Reviewed-by: Slava Egorov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

1 participant