Skip to content

[Android][Impeller]: Graphics Memory Leak #161861

@Demizo

Description

@Demizo

Steps to reproduce

  1. Create an app using Flutter 3.26 or greater with graphically "heavy" widgets (i.e cached images or text shadows)
  2. Build / install / run the apk
  3. Repeatedly redraw the graphically "heavy" widgets. The code sample below uses a bottom navigation bar to allow for quick redraws by switching tabs.
  4. Use DevTools or adb shell dumpsys meminfo "com.example.test" to observe rapidly increasing Graphics memory usage. The graphics memory usage never decreases and eventually the process will be killed after enough redraws.

DevTools memory report in Flutter 3.24 (NO LEAK):

Image

DevTools memory report in Flutter 3.26+:

Image

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int currentIndex = 0;

  final List<Widget> pages = [
    GridView.builder(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 7,
        crossAxisSpacing: 8.0,
        mainAxisSpacing: 8.0,
      ),
      itemBuilder: (context, index) {
        // Example graphically "heavy" widget using text shadows
        return Text(
          "hi",
          style: TextStyle(shadows: [
            Shadow(color: Colors.black.withOpacity(0.8), blurRadius: 4)
          ]),
        );
      },
      itemCount: 7 * 4,
    ),
    SizedBox()
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(child: pages[currentIndex]),
      bottomNavigationBar: NavigationBar(
        labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
        selectedIndex: currentIndex,
        onDestinationSelected: (index) {
          setState(() {
            currentIndex = index;
          });
        },
        destinations: const [
          NavigationDestination(
            icon: Icon(Icons.home_rounded),
            label: 'Home',
          ),
          NavigationDestination(
            icon: Icon(Icons.photo_library_rounded),
            label: 'Gallery',
          ),
        ],
      ),
    );
  }
}

What target platforms are you seeing this bug on?

Android

OS/Browser name and version | Device information

Device: Google Pixel 7, arm 64
OS: Android 15 (API 35)

Does the problem occur on emulator/simulator as well as on physical devices?

No

Logs

Flutter Doctor output

Note: This issue is also present for Flutter version 3.26. The issue does not manifest for Flutter version 3.24 or earlier.

Doctor output
[✓] Flutter (Channel stable, 3.27.1, on NixOS 25.05 (Warbler) 6.6.70, locale en_US.UTF-8)
    • Flutter version 3.27.1 on channel stable at /nix/store/nir2w2fd8xj3i45gmqbbqbcm4kivf1j4-flutter-wrapped-3.27.1-sdk-links
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision nixpkgs000 (), 1970-01-01 00:00:00
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /nix/store/kwfmlf95j6fxfs36l8gz8lz2k5cfi3z7-androidsdk/libexec/android-sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /nix/store/kwfmlf95j6fxfs36l8gz8lz2k5cfi3z7-androidsdk/libexec/android-sdk
    • ANDROID_SDK_ROOT = /nix/store/kwfmlf95j6fxfs36l8gz8lz2k5cfi3z7-androidsdk/libexec/android-sdk
    • Java binary at: /nix/store/k4877vrvzk3pf4k44g1r6k454vjs8f17-openjdk-17.0.13+11/lib/openjdk/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.13+1-nixos)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 19.1.5
    • cmake version 3.30.5
    • ninja version 1.12.1
    • 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/to/linux-android-setup for detailed instructions).

[✓] Connected device (2 available)
    • Pixel 7 (mobile) • Serial Number • android-arm64 • Android 15 (API 35)
    • Linux (desktop)  • linux          • linux-x64     • NixOS 25.05 (Warbler) 6.6.70

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

c: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.perf: memoryPerformance issues related to memoryplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions