这是indexloc提供的服务,不要输入任何密码
Skip to content

Enable the memory observer with full support for releasing memory #8998

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

Merged
merged 14 commits into from
Mar 10, 2025

Conversation

kenzieschmoll
Copy link
Member

@kenzieschmoll kenzieschmoll commented Mar 7, 2025

Add the ability to release memory (see #8997) from the memory pressure prompt (see #8989).

(Ignore the threshold numbers in these gifs. The actual threshold is set to 3.0 GB.)

Successful release of memory upon clicking "Reduce memory":
reduce-success-updated

Unsuccessful release of memory upon clicking "Reduce memory":
reduce-failed-updated

Requires #8997 to land first. Fixes #7002.

@kenzieschmoll kenzieschmoll marked this pull request as ready for review March 7, 2025 19:31
@kenzieschmoll kenzieschmoll requested a review from a team as a code owner March 7, 2025 19:31
@kenzieschmoll kenzieschmoll requested review from elliette and jakemac53 and removed request for a team March 7, 2025 19:31
@kenzieschmoll kenzieschmoll requested a review from bkonyi as a code owner March 7, 2025 21:32
@kenzieschmoll
Copy link
Member Author

This may be less effective in WASM mode, where we are seeing strange results from the measureUserAgentSpecificMemory api: dart-lang/sdk#60280

@kenzieschmoll kenzieschmoll removed the request for review from bkonyi March 7, 2025 22:32
debugMeasureUsageInBytes != null
? await debugMeasureUsageInBytes()
: await measureMemoryUsageInBytes();
_lastMemoryUsageInBytes = memoryUsageInBytes;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just return this as a part of the response (could be a record), as opposed to using a long lived field to keep track of it. And then pass the starting memory usage into reduceMemory as a parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

To pass it into reduceMemory as a parameter, we'd have to make an additional request to measureMemoryUsageInBytes to get the latest value. It is possible that the warning has been showing for a while before the user presses "Reduce memory", so we may not have the most up to date information at the time that we show the prompt. Updating a long lived field here ensures that we always have the latest value available. Calling measureMemoryUsageInBytes is not fast, so calling it again in an onPressed handler wouldn't be a great experience for performance.

@kenzieschmoll kenzieschmoll merged commit f10e8df into flutter:master Mar 10, 2025
41 checks passed
@kenzieschmoll kenzieschmoll deleted the mem-pressure2 branch March 10, 2025 21:38
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.

Prevent DevTools OOMs
2 participants