Skip to content

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

Merged
kenzieschmoll merged 14 commits into
flutter:masterfrom
kenzieschmoll:mem-pressure2
Mar 10, 2025
Merged

kenzieschmoll merged 14 commits into
flutter:masterfrom
kenzieschmoll:mem-pressure2

Conversation

@kenzieschmoll

@kenzieschmoll kenzieschmoll commented Mar 7, 2025 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

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