diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index 463240bf5b..3ccddd2b1e 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -509,6 +509,15 @@ class TrainHoppingAnimation extends Animation this._nextTrain, { this.onSwitchedTrain, }) { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectCreated( + library: 'package:flutter/animation.dart', + className: '$TrainHoppingAnimation', + object: this, + ); + } if (_nextTrain != null) { if (_currentTrain!.value == _nextTrain!.value) { _currentTrain = _nextTrain; @@ -595,6 +604,11 @@ class TrainHoppingAnimation extends Animation /// After this is called, this object is no longer usable. @override void dispose() { + // TODO(polina-c): stop duplicating code across disposables + // https://github.com/flutter/flutter/issues/137435 + if (kFlutterMemoryAllocationsEnabled) { + FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this); + } assert(_currentTrain != null); _currentTrain!.removeStatusListener(_statusChangeHandler); _currentTrain!.removeListener(_valueChangeHandler); diff --git a/packages/flutter/test/animation/animations_test.dart b/packages/flutter/test/animation/animations_test.dart index c0112ab8ed..d88af7da06 100644 --- a/packages/flutter/test/animation/animations_test.dart +++ b/packages/flutter/test/animation/animations_test.dart @@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import '../scheduler/scheduler_tester.dart'; @@ -127,6 +128,19 @@ void main() { expect(animation.toString(), contains('no next')); }); + test('TrainHoppingAnimation dispatches memory events', () async { + await expectLater( + await memoryEvents( + () => TrainHoppingAnimation( + const AlwaysStoppedAnimation(1), + const AlwaysStoppedAnimation(1), + ).dispose(), + TrainHoppingAnimation, + ), + areCreateAndDispose, + ); + }); + test('AnimationMean control test', () { final AnimationController left = AnimationController( value: 0.5,