Skip to content

[Android] [add-to-app] Detaching the |FlutterView| from the engine in Flutter will trigger GC twice. #130379

@0xZOne

Description

@0xZOne

When function |FlutterView#detachFromFlutterEngine| is executed, there will be two |onSurfaceDestroyed| callbacks which in turn trigger two GC operations (Dart_NotifyDestroyed).

In the scenario where multiple FlutterViews reuse the same engine, GC is relatively time-consuming, which slows down the page rendering speed.

1st:
[        ] E/xlog    (24048): 	at io.flutter.embedding.engine.FlutterJNI.onSurfaceDestroyed(FlutterJNI.java:658)
[        ] E/xlog    (24048): 	at io.flutter.embedding.engine.renderer.FlutterRenderer.stopRenderingToSurface(FlutterRenderer.java:373)
[        ] E/xlog    (24048): 	at io.flutter.embedding.android.FlutterView.detachFromFlutterEngine(FlutterView.java:1293)

2nd:
[        ] E/xlog    (24048): 	at io.flutter.embedding.engine.FlutterJNI.onSurfaceDestroyed(FlutterJNI.java:658)
[        ] E/xlog    (24048): 	at io.flutter.embedding.engine.renderer.FlutterRenderer.stopRenderingToSurface(FlutterRenderer.java:373)
[        ] E/xlog    (24048): 	at io.flutter.embedding.android.FlutterTextureView.disconnectSurfaceFromRenderer(FlutterTextureView.java:249)
[        ] E/xlog    (24048): 	at io.flutter.embedding.android.FlutterTextureView.detachFromRenderer(FlutterTextureView.java:174)
[        ] E/xlog    (24048): 	at io.flutter.embedding.android.FlutterView.detachFromFlutterEngine(FlutterView.java:1300)

C9D14CED-A1D1-46BA-BE20-B957FA522D3C

flutter doctor -v
[✓] Flutter (Channel main, 3.13.0-1.0.pre, on macOS 13.1 22C65 darwin-x64, locale zh-Hans-CN)
    • Flutter version 3.13.0-1.0.pre on channel main at /Users/zero/fvm/versions/main
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5345221701 (2 days ago), 2023-07-09 21:01:34 -0400
    • Engine revision 09c6ce4243
    • Dart version 3.1.0 (build 3.1.0-285.0.dev)
    • DevTools version 2.25.0
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/zero/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_SDK_ROOT = /Users/zero/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.79.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.68.0

[✓] Connected device (3 available)
    • NOH AN00 (mobile) • 30.211.97.233:10086 • android-arm64  • Android 12 (API 31)
    • macOS (desktop)   • macos               • darwin-x64     • macOS 13.1 22C65 darwin-x64
    • Chrome (web)      • chrome              • web-javascript • Google Chrome 114.0.5735.198

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: existing-appsIntegration with existing apps via the add-to-app flowengineflutter/engine related. See also e: labels.fyi-androidFor the attention of Android platform teamplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions