flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.35k stars 27.54k forks source link

BUG in [v3.10.0] FlutterViewController memory leak when add an existing app, Multiple Flutter instances #126560

Closed sunchangtan closed 1 year ago

sunchangtan commented 1 year ago

Is there an existing issue for this?

Steps to reproduce

this demo can reproduce https://github.com/flutter/samples/tree/main/add_to_app/multiple_flutters/multiple_flutters_ios

Expected results

FlutterViewController can release normal

Actual results

FlutterViewController memory leak

Code sample

this demo can reproduce https://github.com/flutter/samples/tree/main/add_to_app/multiple_flutters/multiple_flutters_ios

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console [Paste your logs here] ```

Flutter Doctor output

[✓] Flutter (Channel stable, 3.10.0, on macOS 13.3.1 22E772610a darwin-arm64, locale zh-Hans-CN) • Flutter version 3.10.0 on channel stable at /Users/tank/Development/fvm-cache/stable • Upstream repository https://github.com/flutter/flutter.git • Framework revision 84a1e904f4 (2 days ago), 2023-05-09 07:41:44 -0700 • Engine revision d44b5a94c9 • Dart version 3.0.0 • DevTools version 2.23.1 • 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.0) • Android SDK at /Users/tank/Library/Android/sdk • Platform android-33, build-tools 33.0.0 • ANDROID_HOME = /Users/tank/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted.

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

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

[✓] Android Studio (version 2022.2) • 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 17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.1.4) • IntelliJ at /Applications/IntelliJ IDEA.app • 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

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

[✓] Connected device (4 available) • Tank (mobile) • 00008120-0006248A2EF8C01E • ios • iOS 16.4.1 20E252 • iPhone 14 Pro Max (mobile) • D40CC530-5F72-4B9A-B820-84DBC57FB4E9 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.3.1 22E772610a darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 113.0.5672.92

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

• No issues found!

darshankawar commented 1 year ago

@sunchangtan Thanks for the report. When you say memory leak, can you provide a video, a log or screenshot that shows it ? Also, please follow below steps and provide the details so that we can analyze it properly.

  1. flutter run --profile --trace-skia
  2. Record a video of the performance issue using another phone so we can have an intuitive understanding of what happened. Don’t use "adb screenrecord", as that affects the performance of the profile run. Attach the video to your bug.
  3. Open Observatory and save a timeline trace of the performance issue so we know which functions might be causing it. See "How to Collect and Read Timeline Traces" on this blog post: https://medium.com/flutter/profiling-flutter-applications-using-the-timeline-a1a434964af3#a499 Make sure that the performance overlay is turned OFF while recording the trace. Attach the JSON file containing your trace to your bug. You may also wish to include a screenshot of the part of the trace showing the problem you are seeing, just so that people can see at a glance what kind of performance issue the bug is about.

Furthermore, as you mentioned the memory leak in latest version (3.10.0), would be good to have comparison with previous stable so we know and can compare the results properly.

Make sure to verify on latest master version as well, so see if the claimed memory leak is consistent on that version too or not.

sunchangtan commented 1 year ago

@darshankawar Thank you for your response, and I apologize for the delayed reply. Please take a look at the screenshots below. They are Xcode memory analysis and Dart memory analysis respectively. Additionally, I can confirm that Flutter 3.7.12 does not have this issue.

FlutterViewController xcode-memory dart-memory
darshankawar commented 1 year ago

Thanks for the update. Did you run above in --profile mode ? Also does latest master version show the same behavior too ?

sunchangtan commented 1 year ago

Thanks for the update. Did you run above in --profile mode ? Also does latest master version show the same behavior too ?

@darshankawar I run in debug mode and release mode, the laster version 3.10.1 show the same behavior too !

darshankawar commented 1 year ago

Thanks for the update. But we would generally want to run in --profile mode by enabling trace flutter run --profile --trace-skia to properly capture which frames could be causing the leak.

liyunxin commented 1 year ago

I encountered the same BUG in v3.10.1 today, looking forward to solving it.

darshankawar commented 1 year ago

Revisiting the issue, I ran the add_to_app example using stable 3.7.12 and latest version and saw below behavior:

  1. 3.7.12:
Screenshot 2023-05-24 at 11 02 36 AM
  1. 3.10.1 and master:
Screenshot 2023-05-24 at 10 54 45 AM

Based on above verification and original report, going ahead and adding applicable labels for team's input. Currently, won't add regression as I mostly. see similar behavior when it comes to memory usage.

stable, master flutter doctor -v ``` [!] Flutter (Channel stable, 3.10.1, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.10.1 on channel stable at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision d3d8effc68 (35 hours ago), 2023-05-16 17:59:05 -0700 • Engine revision b4fb11214d • Dart version 3.0.1 • DevTools version 2.23.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. [!] Flutter (Channel master, 3.11.0-12.0.pre.28, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.11.0-12.0.pre.28 on channel master at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 216605b60f (63 minutes ago), 2023-05-23 23:40:27 -0400 • Engine revision eebcf36cd3 • Dart version 3.1.0 (build 3.1.0-139.0.dev) • DevTools version 2.23.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/dhs/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13C100 • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 65.1.4 • Dart plugin version 213.7228 [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0 [✓] Connected device (3 available) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 15.3.1 19D52 • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```
myafer commented 1 year ago

I encountered the same BUG in v3.10.1 today, looking forward to solving it.

sunchangtan commented 1 year ago

The issue still exists in version 3.10.3.

cgcym1234 commented 1 year ago

同样遇到

wangzhi8910 commented 1 year ago

The issue still exists in version 3.10.3, looking forward to solving it.

yunhx commented 1 year ago

I found the same BUG in v3.10.0

dadadong commented 1 year ago

The issue still exists in version 3.10.5

chinmaygarde commented 1 year ago

@cyanglaz, there was a reference cycle fixed on the macOS side that looks related to this https://github.com/flutter/engine/commit/6ff02c17268ff8d0dc0cf33c7df0ef76c66cecff. Are you looking into this? If so, just thought to put this on your radar!

AllLuckly commented 1 year ago

Hope to solve this problem as soon as possible, our project has not been launched due to this problem

LinXunFeng commented 1 year ago

I have submitted a PR to solve this problem. flutter/engine#43379

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.