Skip to content

ubuntu desktop app leaks memory #73402

Open

Description

@caijw

Details

**Target Platform: linux
**Target OS version/browser: ubuntu18.04
**Devices:

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.26.0-2.0.pre.179, on Linux, locale en_US.UTF-8)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] VS Code (version 1.51.1)
[✓] Proxy Configuration
[✓] Connected device (2 available)

! Doctor found issues in 2 categories.

flutter ubuntu desktop app comsumes too much memory, and may leaks memory.

build a profile app, and run it.

flutter create app1
cd app1
flutter build linux --profile
./build/linux/profile/bundle/app1

use top to watch this app.

top -p pid

image

RES: ~80M

open the Observatory's allocation-profiler:

image

click the btn in flutter app:

image

the top shows:

image

RES: ~100M

the Observatory's allocation-profiler:

image

trigger gc in Observatory's allocation-profiler:

image

the top shows:

image

RES: ~100M

The above demonstrates that flutter app's RES grows and never decrease.

Logs

Logs

Activity

  1. TahaTesser commented on Jan 6, 2021

    @TahaTesser
    Contributor

    Hi @caijw
    Thanks for filing the issue

    Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  4.1 us,  1.6 sy,  0.0 ni, 94.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
    MiB Mem :  15927.4 total,   6787.0 free,   2452.9 used,   6687.6 buff/cache
    MiB Swap:   4095.5 total,   4095.5 free,      0.0 used.  13018.9 avail Mem 
    
        PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                    
       8364 taha      20   0 1122844 176376  85752 S   0.0   1.1   0:03.64 triage
    flutter doctor -v
    [✓] Flutter (Channel master, 1.26.0-2.0.pre.200, on Linux, locale en_US.UTF-8)
        • Flutter version 1.26.0-2.0.pre.200 at /home/taha/Code/flutter_master
        • Framework revision d0e9959a46 (10 hours ago), 2021-01-05 22:14:03 -0500
        • Engine revision e115066dcd
        • Dart version 2.12.0 (build 2.12.0-179.0.dev)
    
    [✗] Android toolchain - develop for Android devices
        ✗ ANDROID_HOME = /home/taha/Code/sdk
          but Android SDK not found at this location.
    
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    
    [✓] Linux toolchain - develop for Linux desktop
        • Ubuntu clang version 11.0.0-2
        • cmake version 3.16.3
        • ninja version 1.10.0
        • pkg-config version 0.29.2
    
    [!] Android Studio (not installed)
        • Android Studio not found; download from https://developer.android.com/studio/index.html
          (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
    
    [✓] VS Code (version 1.52.0)
        • VS Code at /usr/share/code
        • Flutter extension version 3.17.0
    
    [✓] Connected device (2 available)
        • Linux (desktop) • linux  • linux-x64      • Linux
        • Chrome (web)    • chrome • web-javascript • Google Chrome 87.0.4280.88
    
    ! Doctor found issues in 2 categories.

    Thank you

  2. added
    engineflutter/engine related. See also e: labels.
    perf: memoryPerformance issues related to memory
    platform-linuxBuilding on or for Linux specifically
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Jan 6, 2021
  3. caijw commented on Jan 6, 2021

    @caijw
    ContributorAuthor

    I use valgrind to detect the memory leak.
    The result shows:

    ==00:00:03:56.604 2712== LEAK SUMMARY:
    ==00:00:03:56.604 2712==    definitely lost: 198,056 bytes in 2,654 blocks
    ==00:00:03:56.604 2712==    indirectly lost: 2,537,855 bytes in 18,474 blocks
    ==00:00:03:56.604 2712==      possibly lost: 20,766 bytes in 126 blocks
    ==00:00:03:56.604 2712==    still reachable: 2,309,371 bytes in 30,055 blocks
    ==00:00:03:56.604 2712==                       of which reachable via heuristic:
    ==00:00:03:56.604 2712==                         length64           : 7,312 bytes in 118 blocks
    ==00:00:03:56.604 2712==                         newarray           : 2,312 bytes in 61 blocks
    ==00:00:03:56.604 2712==         suppressed: 0 bytes in 0 blocks
    ==00:00:03:56.604 2712== 
    ==00:00:03:56.604 2712== Use --track-origins=yes to see where uninitialised values come from
    ==00:00:03:56.604 2712== For lists of detected and suppressed errors, rerun with: -s
    ==00:00:03:56.604 2712== ERROR SUMMARY: 2579 errors from 173 contexts (suppressed: 0 from 0)
    

    full valgrind outputs:

    valgrind.log

    The result shows that there is definitely memory leaking.

    It seems that There are up to 3M memory leak. But why the process's RES grows so quickly?

  4. jonahwilliams commented on Jan 6, 2021

    @jonahwilliams
    Contributor

    I don't think the observatory gc button is functional. You're also running a profile mode which still has a debugger attached

  5. caijw commented on Jan 7, 2021

    @caijw
    ContributorAuthor

    I don't think the observatory gc button is functional. You're also running a profile mode which still has a debugger attached

    @jonahwilliams the new generation's memory is freed,so i think the observatory gc button is functional.
    By the way, i test a release app, the process's RES grows too.

    launch:

    image

    click btn:

    image

    image

    Is flutter app trying to consume as much memory as possible?

  6. added
    P2Important issues not at the top of the work list
    on Jan 7, 2021
  7. stuartmorgan-g commented on Feb 20, 2022

    @stuartmorgan-g
  8. huycozy commented on Apr 19, 2024

    @huycozy
    Member

    The issue persists on the latest Flutter stable/master channels.

    • First time app opened:
    top - 19:00:25 up 39 min,  1 user,  load average: 0,55, 0,40, 0,38
    Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  0,7 us,  0,7 sy,  0,0 ni, 98,6 id,  0,1 wa,  0,0 hi,  0,0 si,  0,0 st
    MiB Mem :  15791,1 total,   3383,0 free,   3775,9 used,   8632,1 buff/cache
    MiB Swap:   2048,0 total,   2048,0 free,      0,0 used.  11540,7 avail Mem 
    
        PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                 
      14452 huynq     20   0 1686148 186312  90452 S   0,0   1,2   0:00.38 app1 
    • After triggering action on app (setState on FAB onTap event)
    top - 19:02:16 up 41 min,  1 user,  load average: 0,24, 0,32, 0,35
    Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  0,4 us,  0,3 sy,  0,0 ni, 99,2 id,  0,0 wa,  0,0 hi,  0,0 si,  0,0 st
    MiB Mem :  15791,1 total,   3399,5 free,   3760,4 used,   8631,1 buff/cache
    MiB Swap:   2048,0 total,   2048,0 free,      0,0 used.  11557,9 avail Mem 
    
        PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                 
      14452 huynq     20   0 1689716 196924  92628 S   0,0   1,2   0:02.35 app1
    flutter doctor -v (stable & master)
    [✓] Flutter (Channel stable, 3.19.6, on Ubuntu 22.04.3 LTS 6.5.0-26-generic, locale en_US.UTF-8)
        • Flutter version 3.19.6 on channel stable at /home/huynq/Documents/Working/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 54e66469a9 (2 days ago), 2024-04-17 13:08:03 -0700
        • Engine revision c4cd48e186
        • Dart version 3.3.4
        • DevTools version 2.31.1
    
    [✓] 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: /snap/android-studio/current/jbr/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    
    [✓] Linux toolchain - develop for Linux desktop
        • Ubuntu clang version 14.0.0-1ubuntu1.1
        • cmake version 3.22.1
        • ninja version 1.10.1
        • pkg-config version 0.29.2
    
    [✓] Android Studio (version 2021.1)
        • Android Studio at /home/huynq/Documents/android-studio
        • Flutter plugin version 67.0.1
        • Dart plugin version 211.7817
        • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    
    [!] Android Studio (version unknown)
        • Android Studio at /snap/android-studio/current
        • 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
        ✗ Unable to determine Android Studio version.
        • android-studio-dir = /snap/android-studio/current
        • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /usr/share/code
        • Flutter extension version 3.86.0
    
    [✓] VS Code (version 1.88.1)
        • VS Code at /snap/code/current/usr/share/code
        • Flutter extension version 3.86.0
    
    [✓] Connected device (2 available)
        • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.3 LTS 6.5.0-26-generic
        • Chrome (web)    • chrome • web-javascript • Google Chrome 120.0.6099.199
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    [!] Flutter (Channel master, 3.22.0-14.0.pre.35, on Ubuntu 22.04.3 LTS 6.5.0-26-generic, locale en_US.UTF-8)
        • Flutter version 3.22.0-14.0.pre.35 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 9feccd5f3b (2 hours ago), 2024-04-19 05:08:40 -0400
        • Engine revision 4ed7a2d6ae
        • Dart version 3.5.0 (build 3.5.0-77.0.dev)
        • DevTools version 2.35.0-dev.8
        • 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: /snap/android-studio/current/jbr/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    
    [✓] Linux toolchain - develop for Linux desktop
        • Ubuntu clang version 14.0.0-1ubuntu1.1
        • cmake version 3.22.1
        • ninja version 1.10.1
        • pkg-config version 0.29.2
    
    [✓] Android Studio (version 2021.1)
        • Android Studio at /home/huynq/Documents/android-studio
        • Flutter plugin version 67.0.1
        • Dart plugin version 211.7817
        • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    
    [!] Android Studio (version unknown)
        • Android Studio at /snap/android-studio/current
        • 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
        ✗ Unable to determine Android Studio version.
        • android-studio-dir = /snap/android-studio/current
        • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /usr/share/code
        • Flutter extension version 3.86.0
    
    [✓] VS Code (version 1.88.1)
        • VS Code at /snap/code/current/usr/share/code
        • Flutter extension version 3.86.0
    
    [✓] Connected device (2 available)
        • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.3 LTS 6.5.0-26-generic
        • Chrome (web)    • chrome • web-javascript • Google Chrome 120.0.6099.199
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
  9. added
    team-linuxOwned by the Linux platform team
    and removed on Jun 6, 2024
  10. flutter-triage-bot commented on Jun 6, 2024

    @flutter-triage-bot

    The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.

  11. shbae-musma commented on Aug 31, 2026

    @shbae-musma

    I am seeing what appears to be the same class of issue in a production Flutter Linux HMI: the process RSS and native anonymous memory grow continuously while the Dart heap remains stable.

    Summary

    The application receives real-time some data and updates its UI approximately once per second. The growth is primarily in Anonymous / Private_Dirty, not the Dart heap. Explicit GC in DevTools can reduce memory substantially, but there is no supported way to request GC in a release application.

    The issue is much more pronounced on Raspberry Pi 5 / Linux ARM64 than on Ubuntu x86_64.

    Long-running comparison

    We built the same application source in Flutter Linux release mode and recorded /proc/<pid>/smaps_rollup once per minute.

    Environment Flutter Continuous run RSS slope PSS slope Private Dirty slope Anonymous slope
    Raspberry Pi 5, Ubuntu 26.04 LTS ARM64, X11, Broadcom V3D / Mesa 26.0.8 3.44.9 72.6 h 4.38 MB/h 4.38 MB/h 4.38 MB/h 4.38 MB/h
    Ubuntu 24.04.4 LTS x86_64, X11 3.44.8 84.5 h 0.40 MB/h 0.40 MB/h 0.40 MB/h 0.40 MB/h

    The first 10 minutes were excluded from the linear regressions.

    The last 12-hour slopes were also still positive:

    • Raspberry Pi 5 ARM64: Anonymous +4.97 MB/h
    • Ubuntu x86_64: Anonymous +0.43 MB/h

    On the Raspberry Pi, average anonymous memory increased from approximately 114.8 MB during the first measured 30 minutes to 427.1 MB during the final 30 minutes. On x86_64 it increased from approximately 78.8 MB to 114.3 MB.

    At the end of both tests:

    • swap remained at 0
    • thread count was stable (15 on ARM64, 14 on x86_64)
    • file descriptor count was stable (61)
    • image cache counts were bounded
    • the socket remained connected without reconnection loops

    This suggests that the growth is not caused by accumulating threads, file descriptors, socket connections, or an unbounded Flutter image cache.

    Isolation tests already performed

    We have spent several weeks reducing the application and testing individual paths:

    • Empty Flutter window: stable.
    • Map displayed without repeated UI updates: stable.
    • Socket receive and payload parsing without UI notification/rebuild: stable (Anonymous approximately +0.01 MB/h in the final hour).
    • Socket.IO processing moved into a separate JavaScript process and Flutter input reduced to one batch per second: growth continued in the Flutter process.
    • Mock data generated locally without Socket.IO, followed by a UI update once per second: growth reproduced on Raspberry Pi.
    • Fixed data with notifyListeners() once per second: growth reproduced on Raspberry Pi (approximately +2.1 MB/h in that reduced test).
    • Random allocations once per second without notifying/rebuilding the UI: memory rose initially and then plateaued.
    • Rendering, markers, polylines, circles, labels, map rotation, collision calculations, audio playback, and warning overlays were individually disabled or isolated. They affect the rate, but none alone explains the underlying growth.
    • The behavior was observed with both Skia and Impeller.
    • It was observed on both X11 and Wayland.
    • It was observed on Raspberry Pi OS and Ubuntu ARM64 on the same Raspberry Pi 5 hardware.
    • Software rendering did not eliminate the growth.
    • Dart DevTools heap snapshots did not show retained Dart objects matching the RSS increase.

    The strongest split test was:

    1. Receive and parse the same data, but do not update UI: stable.
    2. Update a fixed UI once per second with no socket input: native anonymous memory grows.

    Current interpretation

    This looks like native memory accumulation associated with repeated Flutter Linux rendering/rebuild work. It may involve the Flutter engine, GTK/Linux embedder, graphics stack, or the native allocator. The effect exists on x86_64 but is amplified by roughly 10x on Raspberry Pi 5 ARM64.

    This resembles the behavior reported in this issue: RSS/native memory grows while Dart GC and heap analysis do not account for the retained process memory. It may also be related in symptoms to #189756, although that report is for Android ARM64 and a high-frequency CustomPainter / paragraph repaint workload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopc: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.found in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onperf: memoryPerformance issues related to memoryplatform-linuxBuilding on or for Linux specificallyteam-linuxOwned by the Linux platform teamtriaged-linuxTriaged by the Linux platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions