Skip to content

Conversation

@ksokolovskyi
Copy link
Contributor

Description

This PR adds DraggableScrollableController creation dispatching in the constructor for memory leak tracking according to dart-lang/leak_tracker#134.

Tests

  • Updates draggable_scrollable_sheet_test.dart to test DraggableScrollableController creation dispatch;
  • Updates draggable_scrollable_sheet_test.dart to add disposal of DraggableScrollableControllers in tests;
  • Updates material/scaffold_test.dart to add disposal of DraggableScrollableControllers in tests;

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. labels Sep 25, 2023
class DraggableScrollableController extends ChangeNotifier {
/// Creates a controller for [DraggableScrollableSheet].
DraggableScrollableController() {
if (kFlutterMemoryAllocationsEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am less familiar here, what is kFlutterMemoryAllocationsEnabled? Will it be on by default in the future? If so, are there plans to come back and remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The kFlutterMemoryAllocationsEnabled is true only in the debug mode. I think setting it to true by default is not needed in production and won't be in the future. In the future, creation/disposal dispatching will be separated into Disposable mixin. You can read about future plans here: https://docs.google.com/document/d/1cjylBOczGk70x-sn1iZYVNAfpPZdtGWsm_KzoNQX0jc/edit#heading=h.b5wf7efqvos

@polina-c, please correct me if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, this flag is only on, when leak tracking is needed.
By default it is on only in debug mode, to tree shake leak tracking code and to have better performance. When needed the flag can be enabled for release and profile mode by compiling with this flag.

ChangeNotifier is special disposable, because it is mixin and thus does not have constructor.
See more details in documentation for maybeDispatchObjectCreation:

static void maybeDispatchObjectCreation(ChangeNotifier object) {

Does it help?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to add maybeDispatchObjectCreation, because DraggableScrollableController leaks in some tests and it is not possible to detect who is owner, that created, but did not dispose the object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok! So eventually in the future we won't need to include kFlutterMemoryAllocationsEnabled in every ChangeNotifier like this? It made me think, hm this should probably be in a lower level of the framework by default so we don't have to remember to include it every time we create a ChangeNotifier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this suggestion is exactly to address this at lower level: https://docs.google.com/document/d/1cjylBOczGk70x-sn1iZYVNAfpPZdtGWsm_KzoNQX0jc/edit#bookmark=id.vp85epkbqmp9

If we forget to include the invocation to the child of ChangeNotifier, it is not big deal, because it can be added after, per instruction for leak troubleshooting, when it is hard to detect who is owner: https://github.com/dart-lang/leak_tracker/blob/main/doc/TROUBLESHOOT.md#1-it-is-not-clear-who-owns-changenotifier

@polina-c polina-c added the a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker label Sep 29, 2023
@polina-c polina-c requested a review from Piinks September 29, 2023 22:10
@polina-c polina-c merged commit fdde241 into flutter:master Sep 30, 2023
@ksokolovskyi
Copy link
Contributor Author

@polina-c, @Piinks, thanks a lot for the review!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 30, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 30, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 30, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Sep 30, 2023
flutter/flutter@57b5c3c...d3df8f6

2023-09-30 [email protected] Roll Flutter Engine from 68fc1a567195 to 01fc3c6624ce (1 revision) (flutter/flutter#135808)
2023-09-30 [email protected] Roll Flutter Engine from 4ed733d99cd5 to 68fc1a567195 (1 revision) (flutter/flutter#135807)
2023-09-30 [email protected] Roll Flutter Engine from d814c69abe26 to 4ed733d99cd5 (1 revision) (flutter/flutter#135801)
2023-09-30 [email protected] Roll Flutter Engine from f726438d4d65 to d814c69abe26 (1 revision) (flutter/flutter#135799)
2023-09-30 [email protected] Roll Flutter Engine from 0b96a82cc874 to f726438d4d65 (1 revision) (flutter/flutter#135796)
2023-09-30 [email protected] Roll Flutter Engine from f3a4cab69962 to 0b96a82cc874 (1 revision) (flutter/flutter#135793)
2023-09-30 [email protected] Roll Flutter Engine from e719b7957763 to f3a4cab69962 (2 revisions) (flutter/flutter#135792)
2023-09-30 [email protected] Roll Flutter Engine from 8939f9c1f4e4 to e719b7957763 (2 revisions) (flutter/flutter#135789)
2023-09-30 [email protected] Roll Flutter Engine from 6a13607008ed to 8939f9c1f4e4 (1 revision) (flutter/flutter#135788)
2023-09-30 [email protected] Add device ready check (flutter/flutter#135526)
2023-09-30 [email protected] Temporarily disable NexusLowRes, version=29 (flutter/flutter#135785)
2023-09-30 [email protected] Cover more test/widgets tests with leak tracking #12. (flutter/flutter#135385)
2023-09-30 [email protected] DraggableScrollableController should dispatch creation in constructor. (flutter/flutter#135423)
2023-09-30 [email protected] Roll Flutter Engine from d203e349781c to 6a13607008ed (2 revisions) (flutter/flutter#135780)
2023-09-29 [email protected] Roll Flutter Engine from 48973d7f9beb to d203e349781c (5 revisions) (flutter/flutter#135776)
2023-09-29 [email protected] ViewportOffset should dispatch creation in constructor. (flutter/flutter#135420)
2023-09-29 [email protected] Use platform dill from the engine when compiling with dart2wasm. (flutter/flutter#134970)
2023-09-29 [email protected] Roll Flutter Engine from d5fcd78a879b to 48973d7f9beb (5 revisions) (flutter/flutter#135765)
2023-09-29 [email protected] Upgrade leak_tracker to fix flackiness. (flutter/flutter#135760)
2023-09-29 [email protected] Roll Flutter Engine from c52251a8b2d0 to d5fcd78a879b (2 revisions) (flutter/flutter#135755)
2023-09-29 [email protected] Update `Drawer` tests for M2/M3 (flutter/flutter#135752)
2023-09-29 [email protected] Expose onAttach and onDetach in ScrollController subclasses (flutter/flutter#135721)
2023-09-29 [email protected] Update the wasm bootstrap to allow access to the emscripten wrapper to skwasm. (flutter/flutter#135723)
2023-09-29 [email protected] Update logic for getting `Analytics` instance from package:unified_analytics (flutter/flutter#134756)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants