Repository navigation
flutter_gpu - potential memory leak on Android (Vulkan) #164278
Description
Steps to reproduce
- Clone the example at https://github.com/kekland/flutter_gpu_memory_leak and run
- The slider on the bottom controls the number of vertices being allocated and subsequently rendered. The change to this value triggers vertex buffer re-allocation.
- To get a memory leak, drag this slider back-and-forth for some time. Frame drops are expected, since the slider's max value is somewhere around a million.
Expected results
No memory leak on Android. The exact same code on macOS seems to not leak anything
Actual results
macOS: Apple Silicon, M3 Pro (18GB), macOS 15.0.1
On macOS there doesn't seem to be a memory leak. After a minute-long run, the memory usage as indicated in the Activity monitor is similar to how it was at the start. Metal system trace indicates roughly equal number of allocations and deallocations for buffers and textures (assume that the discrepancy comes from the actual Flutter rendering itself).
Android: SM-F731B, Android 14, using Impeller with Vulkan on Adreno 740
Running the same app through Android Studio and enabling the Live Telemetry in the Profiler shows the following after a minute or so:
The native allocations: (seems to point towards CommandBuffer and RenderPass usage)
From another run on the latest master:
Arranged by callstack, sorted by remaining size after a 1 minute run:
Code sample
Sample project is at: https://github.com/kekland/flutter_gpu_memory_leak
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
kekland@Erzhans-MacBook-Pro flutter_gpu_memory_leak % fvm flutter doctor -v
[✓] Flutter (Channel master, 3.30.0-1.0.pre.189, on macOS 15.0.1 24A348 darwin-arm64, locale en-US) [5.8s]
• Flutter version 3.30.0-1.0.pre.189 on channel master at /Users/kekland/fvm/versions/master
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 87196771eb (12 days ago), 2025-02-14 16:02:09 -0800
• Engine revision 87196771eb
• Dart version 3.8.0 (build 3.8.0-91.0.dev)
• DevTools version 2.43.0
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc4) [2.6s]
• Android SDK at /Users/kekland/Library/Android/sdk
• Platform android-35, build-tools 35.0.0-rc4
• ANDROID_HOME = /Users/kekland/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 16.0) [1,188ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16A242d
! CocoaPods 1.15.2 out of date (1.16.2 is recommended).
CocoaPods is a package manager for iOS or macOS platform code.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/to/platform-plugins
To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
[✓] Chrome - develop for the web [13ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.2) [13ms]
• 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 21.0.5+-12932927-b750.29)
[✓] VS Code (version 1.97.2) [12ms]
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.105.20250203
[✓] Connected device (4 available) [11.0s]
• SM F731B (mobile) • 192.168.0.20:44079 • android-arm64 • Android 14 (API 34)
• iPhone 16 (mobile) • 365FB7D3-6629-4B3C-B4D8-DF1A375E1509 • ios • com.apple.CoreSimulator.SimRuntime.iOS-18-0 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.0.1 24A348 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 133.0.6943.128
! Error: Browsing on the local area network for Hellomik. Ensure the device is unlocked and attached with a cable or associated with the same local area
network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for Erzhan’s iPhone 11 Pro. Ensure the device is unlocked and attached with a cable or associated with the same
local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources [444ms]
• All expected network resources are available.Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done
Activity
kekland commentedon Feb 27, 2025
Same issue still seems to persist on the latest
master:darshankawar commentedon Feb 27, 2025
This seems to be the foldable device ? https://www.gsmarena.com/samsung_galaxy_z_flip5-12252.php
I tried on S10+ device running Android 11, although the reported behavior didn't seem to occur, but based on the report and findings, I'll keep the issue open for team's tracking.
@kekland Does it still give same result without Impeller ?
kekland commentedon Feb 27, 2025
@darshankawar thanks for a quick response!
Yes, it's a foldable device, but during the test the screen metrics didn't change. @JaffaKetchup had the same memory leak issue, but on another device. I'll try to test it more on a couple of different devices that I have here.
flutter_gpurequires Impeller to run, so I can't disable it for the testJaffaKetchup commentedon Feb 27, 2025
JaffaKetchup commentedon Mar 1, 2025
Running it on my Android 14 device (23090RA98G), I do indeed get the memory leak, although it seems to be a little slower than @kekland's repro. For some reason my Android Studio doesn't show the same level of tabular detail, but it's visible still:
After about 3-4 minutes of running, memory usage grew upwards of half a GB. It's worth saying that in the real use case, the memory growth was much much faster: upwards of 3GB in 2 minutes before a crash.
I would guess that it doesn't make a difference, but running with Vulkan. Trying to run the real use case forcing OpenGL just resulted in nothing at all being rendered to the screen.
7 remaining items
flutter-triage-bot commentedon Jul 16, 2025
This issue is assigned to @bdero but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!
[Flutter GPU] Fix Android/GLES crashers. (#172588)
github-actions commentedon Aug 12, 2025
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 -vand a minimal reproduction of the issue.[Flutter GPU] Fix Android/GLES crashers. (flutter#172588)
[Flutter GPU] Fix Android/GLES crashers. (flutter#172588)
[Tizen] Cherry-pick flutter commit(0b9f406589)
[Flutter GPU] Fix Android/GLES crashers. (flutter#172588)
[Tizen] Cherry-pick flutter commit(0b9f406589)
[Flutter GPU] Fix Android/GLES crashers. (flutter#172588)
[Flutter GPU] Fix Android/GLES crashers. (#172588)