Skip to content

Fix ListView owned ScrollController leak#2200

Open
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-inspection-7341
Open

Fix ListView owned ScrollController leak#2200
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-inspection-7341

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented May 11, 2026

Bug and impact

Recent ListView scroll-control changes create a ScrollController in ListViewState whenever callers do not provide one. That controller was never disposed, so every mount/unmount of a ListView leaked a ChangeNotifier/ScrollController. Repeated navigation through list-heavy screens can accumulate leaked controllers and listeners, increasing memory usage and eventually causing user-facing instability.

Root cause

ListViewState moved ScrollController creation out of ListViewCore to support initialScrollOffset and scroll methods, but did not track whether the state owned that controller or dispose it during teardown.

Fix

Track the internally-created controller in ListViewState and dispose only that owned instance. Externally supplied controllers remain caller-owned.

Validation

  • Added widget regression tests covering owned-controller disposal and external-controller ownership.
  • Attempted to run flutter test modules/ensemble/test/widget/list_view_test.dart, but this runner does not have flutter installed on PATH.
Open in Web View Automation 

Note

Low Risk
Low risk: change is limited to widget lifecycle management and adds tests; main risk is unintended disposal behavior, mitigated by only disposing controllers created internally.

Overview
Fixes a ListView memory leak by tracking whether its ScrollController was created internally and disposing that owned controller in ListViewState.dispose().

Adds widget tests to verify internally-created controllers are disposed on unmount, while caller-provided controllers are left undisposed.

Reviewed by Cursor Bugbot for commit 0087809. Configure here.

Co-authored-by: Sharjeel Yunus <sharjeelyunus@users.noreply.github.com>
@sharjeelyunus sharjeelyunus marked this pull request as ready for review May 11, 2026 12:32
Copy link
Copy Markdown
Author

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0087809. Configure here.

Comment thread modules/ensemble/lib/layout/list_view.dart
@sharjeelyunus sharjeelyunus requested a review from M-Talha4 May 11, 2026 13:13
Co-authored-by: Sharjeel Yunus <sharjeelyunus@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant