Skip to content

[flutter_adaptive_scaffold] Fix some memory leaks [prod-leak-fix] #8546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ValentinVignal
Copy link
Contributor

Fixes some memory leaks

See the documentation: https://github.com/dart-lang/leak_tracker/blob/main/doc%2Fleak_tracking%2FDETECT.md

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@ValentinVignal
Copy link
Contributor Author

cc @polina-c

@ValentinVignal
Copy link
Contributor Author

More leaks must be fixed so we cannot yet activate leak testing on the package. I'd have 2 questions around that

  1. This PR doesn't contain any test, the test would be to activate leak testing. Is this PR exempted from tests or is it better to activate leak testing the tests that got fix with experimentalLeakTesting: LeakTesting.settings.withTrackedAll(), ?
  2. Here are some leaks that we cannot easily fix:
    /// Fade in animation.
    static Widget fadeIn(Widget child, Animation<double> animation) {
    return FadeTransition(
    opacity: CurvedAnimation(parent: animation, curve: Curves.easeInCubic),
    child: child,
    );
    }
    /// Fade out animation.
    static Widget fadeOut(Widget child, Animation<double> animation) {
    return FadeTransition(
    opacity: CurvedAnimation(
    parent: ReverseAnimation(animation),
    curve: Curves.easeInCubic,
    ),
    child: child,
    );
    }

    Those static method create CurvedAnimations that never get disposed. They are then used in a build method:
    body: SlotLayout(
    config: <Breakpoint, SlotLayoutConfig?>{
    Breakpoints.standard: SlotLayout.from(
    key: const Key('body'),
    inAnimation: AdaptiveScaffold.fadeIn,
    outAnimation: AdaptiveScaffold.fadeOut,
    builder: widget.body,
    ),

How do you suggest with can fix them?

@ValentinVignal
Copy link
Contributor Author

Any feedback on this @gspencergoog ?

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Thanks for the fixes!

Copy link

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

LGTM thank you! It looks like there are some merge conflicts, can you take a look? After resolving those we can land this. 🎊

@ValentinVignal
Copy link
Contributor Author

Sure I'll fix them

Do you have any suggestion on how to "fix" the static method (ex: fadeIn and fadeOut). They create CurvedAnimations that are not disposed.

Are we willing to do breaking changes? If not, what would be the best approach?

@ValentinVignal
Copy link
Contributor Author

Oh never mind, I just saw the readme saying it is dis-continuated. Is it still worth spending effort on it?

@Piinks
Copy link
Contributor

Piinks commented Feb 14, 2025

We can still land this change, I really appreciate your work on this. :)
To follow up on potential new forks/maintainers of this package see flutter/flutter#162965

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 14, 2025
@auto-submit auto-submit bot merged commit c643081 into flutter:main Feb 14, 2025
82 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 17, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Feb 17, 2025
flutter/packages@625023a...8542af3

2025-02-15 [email protected] [various] Enable `permissive-` for
Windows plugin examples (flutter/packages#8636)
2025-02-15 [email protected] [pigeon] Update task queue handling
(flutter/packages#8627)
2025-02-14 [email protected] Update CODEOWNERS
(flutter/packages#8628)
2025-02-14 [email protected]
[flutter_adaptive_scaffold] Fix some memory leaks
(flutter/packages#8546)
2025-02-14 [email protected] [camera] Fix crash when
setting activeFormat on FLTCaptureDevice (flutter/packages#8630)
2025-02-13 [email protected] [camera] Remove remaining
OCMock usage in tests (flutter/packages#8624)
2025-02-13 [email protected]
[webview_flutter_wkwebview] Change callback methods with a non-null
return type to non-null (flutter/packages#8564)
2025-02-12 [email protected]
[google_sign_in_ios] Adds Swift Package Manager support
(flutter/packages#7356)
2025-02-12 [email protected] [camera_avfoundation] Migrate
tests to Swift - part 1 (flutter/packages#8603)
2025-02-12 [email protected] [video_player]
Re-enables `asset videos live stream duration != 0` test for Android
(flutter/packages#8610)
2025-02-12 [email protected]
[go_router_builder] Add support for `TypedStatefulShellBranch`'s
`preload` (flutter/packages#8587)
2025-02-12 [email protected] [local_auth_darwin] Fix test name for
clarity (flutter/packages#8499)
2025-02-11 [email protected] [ci] Manually roll master, set -Xmx4G
(flutter/packages#8586)
2025-02-11 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump the gradle-plugin group across 4 directories with 1
update (flutter/packages#8551)
2025-02-10 [email protected] [pigeon] Add
errors for ProxyAPI callback methods and null instances when reading in
a ProxyApiBaseCodec (flutter/packages#8567)
2025-02-10 [email protected]
[shared_preferences]Fix : SetState returning future
(flutter/packages#8398)
2025-02-10 [email protected] [various] Add deprecation notices to
READMEs (flutter/packages#8598)
2025-02-10 [email protected] [camera] Remove OCMock from
CameraSettingsTests, CameraMethodChannelTests and
CameraSessionPresetsTests (flutter/packages#8592)
2025-02-10 [email protected] [camera] Remove OCMock from
FLTCamPhotoCaptureTests, FLTSavePhotoDelegateTests and StreamingTests
(flutter/packages#8590)
2025-02-07 [email protected] [go_router]
Add `preload` parameter to `StatefulShellBranchData.$branch`
(flutter/packages#8545)
2025-02-07 [email protected] [video_player_avfoundation] iOS
platform view support (flutter/packages#8237)

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-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

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

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@polina-c polina-c added the a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker label Feb 20, 2025
@polina-c polina-c changed the title [flutter_adaptive_scaffold] Fix some memory leaks [flutter_adaptive_scaffold] Fix some memory leaks [prod-leak-fix] Feb 20, 2025
@hanskokx
Copy link

hanskokx commented Feb 24, 2025

We can still land this change, I really appreciate your work on this. :) To follow up on potential new forks/maintainers of this package see flutter/flutter#162965

I pulled these changes into my fork! Are there any other changes I might be missing that should also be pulled in?

@ValentinVignal
Copy link
Contributor Author

@hanskokx there is no more changes to pull (from this PR at least).

However, the design of the package creates memory leaks and should be changed in my opinion.

Those memory leaks can be detected with leak_tracker https://github.com/dart-lang/leak_tracker/blob/main/doc%2Fleak_tracking%2FDETECT.md

Some detected memory leaks are from the CurvedAnimation that are never disposed:

/// Fade in animation.
static Widget fadeIn(Widget child, Animation<double> animation) {
return FadeTransition(
opacity: CurvedAnimation(parent: animation, curve: Curves.easeInCubic),
child: child,
);
}
/// Fade out animation.
static Widget fadeOut(Widget child, Animation<double> animation) {
return FadeTransition(
opacity: CurvedAnimation(
parent: ReverseAnimation(animation),
curve: Curves.easeInCubic,
),
child: child,
);
}

Those static methods create CurvedAnimations that never get disposed. They are then used in a build method:
body: SlotLayout(
config: <Breakpoint, SlotLayoutConfig?>{
Breakpoints.standard: SlotLayout.from(
key: const Key('body'),
inAnimation: AdaptiveScaffold.fadeIn,
outAnimation: AdaptiveScaffold.fadeOut,
builder: widget.body,
),

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 autosubmit Merge PR when tree becomes green via auto submit App p: flutter_adaptive_scaffold
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants