Skip to content

Prevent GC of value during async eval#9885

Open
srawlins wants to merge 4 commits into
flutter:masterfrom
srawlins:eval-gc
Open

Prevent GC of value during async eval#9885
srawlins wants to merge 4 commits into
flutter:masterfrom
srawlins:eval-gc

Conversation

@srawlins

@srawlins srawlins commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Gemini suggests this to reduce flakiness in integration tests, some of which strongly rely on eval. Gemini looked at recent failed integration tests to suggest this.

@srawlins srawlins requested a review from kenzieschmoll as a code owner July 9, 2026 21:10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes garbage collection issues with the result list in asyncEval on both native VM and web by keeping a strong reference to the reader object in the target app until the future resolves. The reviewer pointed out that using Timer.periodic inside the evaluated expression might fail if the target library does not explicitly import dart:async. They suggested using an asynchronous loop with Future.delayed instead, as Future is part of dart:core and guaranteed to be available in any Dart library context.

Comment thread packages/devtools_app_shared/lib/src/service/eval_on_dart_library.dart Outdated
Comment thread packages/devtools_app_shared/lib/src/service/eval_on_dart_library.dart Outdated
@srawlins srawlins requested a review from a team as a code owner July 13, 2026 17:58
@srawlins srawlins requested review from bkonyi and removed request for a team July 13, 2026 17:58
## Debugger updates

TODO: Remove this section if there are not any updates.
* Prevent values from being garbage-collected, while being evaluated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add link to PR

' for (int i = 0; i < 100; i++) {'
' final _ = reader;'
' await Future.delayed(const Duration(milliseconds: 50));'
' /* Stop pinning after a 1-second buffer when the future has completed. */'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we using /* instead of // ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this is all one line of code. So we can't use EOL comments.

' final _ = reader;'
' await Future.delayed(const Duration(milliseconds: 50));'
' /* Stop pinning after a 1-second buffer when the future has completed. */'
' if (isDone || ++bufferTicks > 20) break;'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the change from 100 to 20 intentional?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if so, we don't need to loop 100 times since we will always short circuit at 20. We can just change the for loop to a while loop

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

Successfully merging this pull request may close these issues.

2 participants