-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Awaiting a static variable Future in async/await closure leaks too many object references #42457
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
Comments
Has there been any work in this area? This can cause accidental leaks of native resources in Flutter applications, and there doesn't seem to be much I can do to mitigate these issues. |
The fact that closure contexts are capturing more than necessary as well as not null-ing out references in the context once it's not needed anymore is a known issue. See also #36983 Fixing the general issue is probably a bigger undertaking, so it needs to be high up on the priority list for us to invest in changing this. Fixing it might also reduce usability to a certain extend. Because the debugger in JIT would - when hitting a breakpoint in a function - suddently show variables as Maybe we can mark this as a duplicate of #36983 ? |
In some cases the closure context can have a direct reference to something large, so the Closure stashed by the Context, maybe its worth optionally allowing JIT mode to opt into more restrictive Contexts via a flag. |
The particular I think it makes sense to abstract this logic out of runtime/vm/stack_trace.cc and make it usable in runtime/vm/debugger.cc and completely remove the @cskau-g Can you look into this? |
Changes debugger.cc to use the 'lazy async stack' mechanism for unwinding async stacks, which means we no longer have to manually keep track of the caller. This also allows us to get rid of _asyncStarListenHelper. Bug: #42457 Change-Id: I536e9da4af275998140ae5f05e3a43e07c77cfc7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167561 Commit-Queue: Clement Skau <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
This is done with the above change. I'm not sure if that's the extent of what we wanted to track in the issue or not, but I'll go ahead and close it since the mentioned part is resolve. |
If you have a
Future
which is retained by GC because it is in the static fields table, it will leak everything in the context of anyasync
closure whichawait
s it.For example:
By the time
main
is complete I hope forSomethignBIg
to no longer be retained, however it is still reachable:After running the following,
SomethingBig
is able to be garbage collected, because the_valueOrListeners
field stops holding the listener after it no longer needs it.The text was updated successfully, but these errors were encountered: