-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
toImageSync retains display list which can lead to surprising memory retention. #138627
Comments
I ran your sample code and can reproduce it on Linux and macOS Flutter app. It doesn't seem to occur on Web platform. flutter doctor -v (stable & master)[✓] Flutter (Channel stable, 3.16.0, on Ubuntu 22.04.3 LTS 6.2.0-36-generic, locale en_US.UTF-8)
• Flutter version 3.16.0 on channel stable at /home/huynq/Documents/Working/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision db7ef5bf9f (5 days ago), 2023-11-15 11:25:44 -0800
• Engine revision 74d16627b9
• Dart version 3.2.0
• DevTools version 2.28.2
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc3)
• Android SDK at /home/huynq/Android/Sdk/
• Platform android-33, build-tools 34.0.0-rc3
• Java binary at: /home/huynq/Documents/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• clang version 10.0.0-4ubuntu1
• cmake version 3.22.1
• ninja version 1.10.1
• pkg-config version 0.29.2
[✓] Android Studio (version 2022.3)
• Android Studio at /snap/android-studio/128/android-studio
• Flutter plugin version 76.2.2
• 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.6b829.9-10027231)
[✓] Android Studio (version 2021.1)
• Android Studio at /home/huynq/Documents/android-studio/
• Flutter plugin version 67.0.1
• Dart plugin version 211.7817
• android-studio-dir = /home/huynq/Documents/android-studio/
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
[✓] VS Code (version 1.83.1)
• VS Code at /usr/share/code
• Flutter extension version 3.76.0
[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.3 LTS 6.2.0-36-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 118.0.5993.70
[✓] Network resources
• All expected network resources are available.
• No issues found! [!] Flutter (Channel master, 3.17.0-10.0.pre.61, on Ubuntu 22.04.3 LTS 6.2.0-36-generic, locale en_US.UTF-8)
• Flutter version 3.17.0-10.0.pre.61 on channel master at /home/huynq/Documents/Working/flutter_master
! Warning: `flutter` on your path resolves to /home/huynq/Documents/Working/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /home/huynq/Documents/Working/flutter_master. Consider adding /home/huynq/Documents/Working/flutter_master/bin to the front of your path.
! Warning: `dart` on your path resolves to /home/huynq/Documents/Working/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /home/huynq/Documents/Working/flutter_master. Consider adding /home/huynq/Documents/Working/flutter_master/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d2b67d4cea (2 hours ago), 2023-11-20 01:06:28 -0500
• Engine revision e916d5bfdd
• Dart version 3.3.0 (build 3.3.0-149.0.dev)
• DevTools version 2.30.0-dev.4
• 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 34.0.0-rc3)
• Android SDK at /home/huynq/Android/Sdk/
• Platform android-33, build-tools 34.0.0-rc3
• Java binary at: /home/huynq/Documents/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• clang version 10.0.0-4ubuntu1
• cmake version 3.22.1
• ninja version 1.10.1
• pkg-config version 0.29.2
[✓] Android Studio (version 2022.3)
• Android Studio at /snap/android-studio/128/android-studio
• Flutter plugin version 76.2.2
• 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.6b829.9-10027231)
[✓] Android Studio (version 2021.1)
• Android Studio at /home/huynq/Documents/android-studio/
• Flutter plugin version 67.0.1
• Dart plugin version 211.7817
• android-studio-dir = /home/huynq/Documents/android-studio/
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
[✓] VS Code (version 1.83.1)
• VS Code at /usr/share/code
• Flutter extension version 3.76.0
[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.3 LTS 6.2.0-36-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 118.0.5993.70
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category. |
@alnitak It doesn't look like you are ever disposing the image objects. This may result in your application running out of memory, as you are relying on the Dart GC to clear objects that are holding onto substantial native memory. Its not obvious to me that there is a specific bug with setImageSampler, but this could use more investigation at any rate. |
It looks like its disposing the previous image each tick: And disposing the current picture after the image has been acquired: Would this still be considered leaving it to GC? |
Yeah good point, but it also looks like this creates an endless chain of sampler 1 -> sampler 2 -> sampler 1. Since toImageSync stores its display list that is likely keeping all images alive indefinitely |
FYI @dnfield @jason-simmons I think this is actually an issue with toImageSync |
Thanks for your time looking at this. I would also like to highlight the fact that I don't notice any increasing memory while monitoring memory on DevTools, the Dart GC seems normal, but just looking at the OS memory monitor. |
The object returned by So if the picture created on the current tick uses the If the previous tick's The asynchronous |
Perhaps this is an example of a case where we should provide some sort of flattening operation, or the ability to create host resident textures (to ensure we don't need to retain a display list to recreate them). |
This issue seems related to the closed #131524 |
Is there an existing issue for this?
Steps to reproduce
Actual results
All the PC memory get filled till system crash
Code sample
I have created a public GitHub project as short as I could.
Some more info in the README.md
Screenshots or Video
After about 40~60 seconds memory leak is starting growing till it reach 100%.
DevTools memory tab doesn't show memory leaks.
Screenshots
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: