Unverified Commit ca384b84 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

Ticker should dispatch creation and disposal events. (#137844)

parent 89692884
......@@ -71,6 +71,15 @@ class Ticker {
_debugCreationStack = StackTrace.current;
return true;
}());
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/scheduler.dart',
className: '$Ticker',
object: this,
);
}
}
TickerFuture? _future;
......@@ -319,6 +328,12 @@ class Ticker {
/// with a [TickerCanceled] error.
@mustCallSuper
void dispose() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
if (_future != null) {
final TickerFuture localFuture = _future!;
_future = null;
......
......@@ -23,6 +23,7 @@ void main() {
}
final Ticker ticker = Ticker(handleTick);
addTearDown(ticker.dispose);
expect(ticker.isTicking, isFalse);
expect(ticker.isActive, isFalse);
......@@ -100,6 +101,7 @@ void main() {
testWidgetsWithLeakTracking('Ticker control test', (WidgetTester tester) async {
late Ticker ticker;
addTearDown(() => ticker.dispose());
void testFunction() {
ticker = Ticker((Duration _) { });
......@@ -154,6 +156,7 @@ void main() {
}
final Ticker ticker = Ticker(handleTick);
addTearDown(ticker.dispose);
ticker.start();
expect(ticker.isTicking, isTrue);
......@@ -179,6 +182,7 @@ void main() {
}
final Ticker ticker = Ticker(handleTick);
addTearDown(ticker.dispose);
ticker.start();
expect(tickCount, equals(0));
......@@ -198,4 +202,11 @@ void main() {
ticker.stop();
});
test('Ticker dispatches memory events', () async {
await expectLater(
await memoryEvents(() => Ticker((_) {}).dispose(), Ticker,),
areCreateAndDispose,
);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment