Skip to content

Android embedding does not call Shell::NotifyLowMemoryWarning when there is memory pressure #59182

@dnfield

Description

@dnfield

It just sends the system channel notification, which the engine does not listen for specially.

We could fix this by either making the engine (i.e. in engine.cc) listen for this channel message like others and notify the shell when it hears the message (and then forward it along), or we could expose the shell call through the JNI bindings so that we can do it the way it's done on iOS and in the embedder API.

If we update the engine.cc for this, we should take out the iOS/embedder portions. If we update Android for it, we just have to make sure we're consistent.

One other possible issue that comes to mind is that we may want to try to call Dart_NotifyLowMemory after we send the channel message, on the off chance that the Dart code has enough time to actually free some caches to let the garbage collector pick up even more garbage.

References:

New embedding:

https://github.com/flutter/engine/blob/a6435210acaee2fcd4f0f049032c47c043cfd51f/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java#L636
https://github.com/flutter/engine/blob/a6435210acaee2fcd4f0f049032c47c043cfd51f/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java#L654

Old embedding:

https://github.com/flutter/engine/blob/a6435210acaee2fcd4f0f049032c47c043cfd51f/shell/platform/android/io/flutter/view/FlutterView.java#L323

Compare with iOS:
https://github.com/flutter/engine/blob/a6435210acaee2fcd4f0f049032c47c043cfd51f/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm#L747-L750

Compare with Embedder API:
https://github.com/flutter/engine/blob/a6435210acaee2fcd4f0f049032c47c043cfd51f/shell/platform/embedder/embedder.cc#L1840-L1853

@xster @matthew-carroll @jason-simmons @chinmaygarde for input.

Metadata

Metadata

Assignees

Labels

P0Critical issues such as a build break or regressionc: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.perf: memoryPerformance issues related to memoryplatform-androidAndroid applications specifically

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions