Skip to content
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

BackgroundIsolateBinaryMessenger leak memory on IOS #122792

Closed
BenoitOutman opened this issue Mar 16, 2023 · 5 comments · Fixed by flutter/engine#40373
Closed

BackgroundIsolateBinaryMessenger leak memory on IOS #122792

BenoitOutman opened this issue Mar 16, 2023 · 5 comments · Fixed by flutter/engine#40373
Labels
engine flutter/engine repository. See also e: labels. found in release: 3.7 Found to occur in 3.7 found in release: 3.9 Found to occur in 3.9 has reproducible steps The issue has been confirmed reproducible and is ready to work on perf: memory Performance issues related to memory platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version

Comments

@BenoitOutman
Copy link

Details

Hello, I'm trying to implement the BackgroundIsolateBinaryMessenger as described here: https://medium.com/flutter/introducing-background-isolate-channels-7a299609cad8 but it seems that on iOS the data is never released and therefore the memory used increases until the application crashes.

I made a sample with a simple plugin who send Uint8List, you can run the example project to try it.
https://github.com/BenoitOutman/BackgroundIsolateBinaryMessengerLeak

same issue on master channel

**Target Platform: IOS
**Target OS version/browser:14.7.1
**Devices: iphone 6S and Iphone 12 mini simulator

Logs

Logs

[✓] Flutter (Channel stable, 3.7.7, on macOS 13.2.1 22D68 darwin-x64, locale fr-FR)
• Flutter version 3.7.7 on channel stable at /Users/atombu/fvm/versions/stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2ad6cd7 (8 days ago), 2023-03-08 09:41:59 -0800
• Engine revision 1837b5be5f
• Dart version 2.19.4
• DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/atombu/Library/Android/sdk
• Platform android-33, build-tools 30.0.3
• Java binary at: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
• Java version Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
• 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)

[✓] IntelliJ IDEA Community Edition (version 2020.2.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 52.2.3
• Dart plugin version 202.8531

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

[✓] Connected device (5 available)
• SM A530F (mobile) • 5200f39c43a5b545 • android-arm64 • Android
8.0.0 (API 26) (emulator)
• iPhone de Yannick (mobile) • 01008c8ec0b7bd4655f6c3d21d009e2bd7af41e6 • ios • iOS 14.7.1
18G82
• iPhone 12 mini (mobile) • D47E2D66-50D6-4B63-AFCA-1F716E8789E6 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS
13.2.1 22D68 darwin-x64
• Chrome (web)
• chrome • web-javascript • Google
Chrome 111.0.5563.64

[✓] HTTP Host Availability
• All required HTTP hosts are available

• No issues found!

![Capture d’écran 2023-03-16 à 09 54 36](https://user-images.githubusercontent.com/46782918/225582941-86de6ca2-a090-4b11-be88-8b273e40aa9d.png)
@BenoitOutman BenoitOutman added the from: performance template Issues created via a performance issue template label Mar 16, 2023
@danagbemava-nc danagbemava-nc removed the from: performance template Issues created via a performance issue template label Mar 16, 2023
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Mar 16, 2023
@darshankawar
Copy link
Member

@BenoitOutman
Are you getting this in debug mode or in profile mode ? Usually performance related issues need to be run in --profile mode and with physical device preferably to get actual behavior. Also, please provide timeline trace by running flutter run --profile --trace-skia so that it'll help to know which frames are expensive.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 16, 2023
@BenoitOutman
Copy link
Author

The sample does not display anything but a text, the problem is not a display performance issue but a memory leak issue due to the use of BackgroundIsolateBinaryMessenger

The iphone 6s is a real device and the issue is in debug, profile, and release mode

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 16, 2023
jason-simmons added a commit to jason-simmons/flutter_engine that referenced this issue Mar 17, 2023
With background platform isolate channels, the handler can be invoked
on threads that are created by Dart and do not already have an
autorelease pool.

Fixes flutter/flutter#122792
@darshankawar
Copy link
Member

Thanks for the feedback.
Using the code sample provided and running on iPhone 6s, do see the same behavior as reported.

stable, master flutter doctor -v
[!] Flutter (Channel stable, 3.7.6, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.7.6 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 12cb4eb7a0 (8 days ago), 2023-03-01 10:29:26 -0800
    • Engine revision ada363ee93
    • Dart version 2.19.3
    • DevTools version 2.20.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.9.0-7.0.pre.32, on macOS 12.2.1 21D62 darwin-x64,
    locale en-GB)
    • Flutter version 3.9.0-7.0.pre.32 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 e2e313ecf6 (3 hours ago), 2023-03-14 19:13:21 -0700
    • Engine revision e80266b78e
    • Dart version 3.0.0 (build 3.0.0-322.0.dev)
    • DevTools version 2.22.2
    • 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.



@darshankawar darshankawar added platform-ios iOS applications specifically engine flutter/engine repository. See also e: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.7 Found to occur in 3.7 found in release: 3.9 Found to occur in 3.9 perf: memory Performance issues related to memory and removed in triage Presently being triaged by the triage team labels Mar 17, 2023
@jmagman
Copy link
Member

jmagman commented Mar 17, 2023

cc @gaaclarke

@github-actions
Copy link

github-actions bot commented Apr 3, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
engine flutter/engine repository. See also e: labels. found in release: 3.7 Found to occur in 3.7 found in release: 3.9 Found to occur in 3.9 has reproducible steps The issue has been confirmed reproducible and is ready to work on perf: memory Performance issues related to memory platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants