Skip to content

flutter_gpu - potential memory leak on Android (Vulkan) #164278

Closed

Description

@kekland

Steps to reproduce

  1. Clone the example at https://github.com/kekland/flutter_gpu_memory_leak and run
  2. 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.
  3. 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).

Image

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:

Image

The native allocations: (seems to point towards CommandBuffer and RenderPass usage)

Image

From another run on the latest master:

Image

Arranged by callstack, sorted by remaining size after a 1 minute run:

Image

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.

Activity

  1. kekland commented on Feb 27, 2025

    @kekland
    Author

    Same issue still seems to persist on the latest master:

    kekland@Erzhans-MacBook-Pro flutter_gpu_memory_leak % fvm flutter doctor -v
    [✓] Flutter (Channel master, 3.30.0-1.0.pre.364, on macOS 15.0.1 24A348 darwin-arm64, locale en-US) [2.9s]
        • Flutter version 3.30.0-1.0.pre.364 on channel master at /Users/kekland/fvm/versions/master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f1f463c767 (2 hours ago), 2025-02-27 01:56:39 -0500
        • Engine revision f1f463c767
        • Dart version 3.8.0 (build 3.8.0-147.0.dev)
        • DevTools version 2.43.0
    
  2. darshankawar commented on Feb 27, 2025

    @darshankawar
    Member

    Android: SM-F731B, Android 14, using Impeller with Vulkan on Adreno 740

    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 ?

  3. moved this to 🤔 Needs Triage in Flutter GPUon Feb 27, 2025
  4. kekland commented on Feb 27, 2025

    @kekland
    Author

    @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_gpu requires Impeller to run, so I can't disable it for the test

  5. JaffaKetchup commented on Feb 27, 2025

    @JaffaKetchup
  6. JaffaKetchup commented on Mar 1, 2025

    @JaffaKetchup
    Contributor

    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:

    Image

    Image

    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. 7 remaining items

  8. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Jul 16, 2025
  9. flutter-triage-bot commented on Jul 16, 2025

    @flutter-triage-bot

    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!

  10. moved this from 🤔 Needs Triage to ✅ Done in Flutter GPUon Jul 28, 2025
  11. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jul 29, 2025
  12. github-actions commented on Aug 12, 2025

    @github-actions

    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.

  13. locked as resolved and limited conversation to collaborators on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

⏳Bot is counting down the days until it unassigns the issueP3Issues that are less important to the Flutter projectflutter-gpur: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions