Skip to content

Memory leak in InteractiveViewer: CurvedAnimation repeatedly instantiated #185825

Description

@adil192

This bug was discovered following #185468

Steps to reproduce

  1. Perform a "fling" gesture on an InteractiveViewer repeatedly.
  2. Observe that CurvedAnimation gets created multiple times without getting disposed.

Expected results

CurvedAnimation should either get disposed or be replaced with CurveTween.

Actual results

CurvedAnimation gets created multiple times (in _onScaleEnd) without getting disposed.

Code sample

Code sample
    testWidgets('does not accumulate listeners', (WidgetTester tester) async {
      await tester.pumpWidget(
        InteractiveViewer(
          transformationController: transformationController,
          child: const SizedBox(width: 2000.0, height: 2000.0),
        ),
      );

      final List<ObjectEvent> events = await memoryEvents(() async {
        for (var i = 0; i < 10; ++i) {
          await tester.fling(find.byType(InteractiveViewer), const Offset(0, -100), 3000);
          await tester.pump();
        }
      }, CurvedAnimation);
      expect(
        events,
        hasLength(lessThanOrEqualTo(2)),
        reason: 'CurvedAnimation must not be repeatedly created without disposal.',
      );
    });

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
ahann@dellpro:~$ flutter doctor -v

┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
[✓] Flutter (Channel stable, 3.41.7, on Ultramarine Linux 44 (Placeholder) 7.0.1-cachyos1.fc44.x86_64, locale
    en_GB.UTF-8) [78ms]
    • Flutter version 3.41.7 on channel stable at /home/ahann/Documents/Sources/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cc0734ac71 (2 weeks ago), 2026-04-15 21:21:08 -0700
    • Engine revision 59aa584fdf
    • Dart version 3.11.5
    • DevTools version 2.54.2
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop,
      enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file,
      enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [2.8s]
    • Android SDK at /home/ahann/Android/Sdk
    • Emulator version 36.5.11.0 (build_id 15261927) (CL:N/A)
    • Platform android-36, build-tools 36.1.0
    • ANDROID_HOME = /home/ahann/Android/Sdk
    • Java binary at: /home/ahann/.local/share/JetBrains/Toolbox/apps/android-studio/jbr/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.10+-14961533-b1163.108)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [18ms]
    • CHROME_EXECUTABLE =
      /home/ahann/.local/share/flatpak/app/org.chromium.Chromium/x86_64/stable/active/export/bin/org.chromium.C
      hromium

[✓] Linux toolchain - develop for Linux desktop [643ms]
    • clang version 22.1.2 (Fedora 22.1.2-1.fc44)
    • cmake version 4.3.0
    • ninja version 1.13.2
    • pkg-config version 2.5.1
    • OpenGL core renderer: Mesa Intel(R) Graphics (LNL)
    • OpenGL core version: 4.6 (Core Profile) Mesa 26.1.0-rc2
    • OpenGL core shading language version: 4.60
    • OpenGL ES renderer: Mesa Intel(R) Graphics (LNL)
    • OpenGL ES version: OpenGL ES 3.2 Mesa 26.1.0-rc2
    • OpenGL ES shading language version: OpenGL ES GLSL ES 3.20
    • GL_EXT_framebuffer_blit: yes
    • GL_EXT_texture_format_BGRA8888: yes

[✓] Connected device (2 available) [379ms]
    • Linux (desktop) • linux  • linux-x64      • Ultramarine Linux 44 (Placeholder) 7.0.1-cachyos1.fc44.x86_64
    • Chrome (web)    • chrome • web-javascript • Chromium 147.0.7727.116

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

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: animationAnimation APIsframeworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flight

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions