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 { ...@@ -71,6 +71,15 @@ class Ticker {
_debugCreationStack = StackTrace.current; _debugCreationStack = StackTrace.current;
return true; 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; TickerFuture? _future;
...@@ -319,6 +328,12 @@ class Ticker { ...@@ -319,6 +328,12 @@ class Ticker {
/// with a [TickerCanceled] error. /// with a [TickerCanceled] error.
@mustCallSuper @mustCallSuper
void dispose() { 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) { if (_future != null) {
final TickerFuture localFuture = _future!; final TickerFuture localFuture = _future!;
_future = null; _future = null;
......
...@@ -23,6 +23,7 @@ void main() { ...@@ -23,6 +23,7 @@ void main() {
} }
final Ticker ticker = Ticker(handleTick); final Ticker ticker = Ticker(handleTick);
addTearDown(ticker.dispose);
expect(ticker.isTicking, isFalse); expect(ticker.isTicking, isFalse);
expect(ticker.isActive, isFalse); expect(ticker.isActive, isFalse);
...@@ -100,6 +101,7 @@ void main() { ...@@ -100,6 +101,7 @@ void main() {
testWidgetsWithLeakTracking('Ticker control test', (WidgetTester tester) async { testWidgetsWithLeakTracking('Ticker control test', (WidgetTester tester) async {
late Ticker ticker; late Ticker ticker;
addTearDown(() => ticker.dispose());
void testFunction() { void testFunction() {
ticker = Ticker((Duration _) { }); ticker = Ticker((Duration _) { });
...@@ -154,6 +156,7 @@ void main() { ...@@ -154,6 +156,7 @@ void main() {
} }
final Ticker ticker = Ticker(handleTick); final Ticker ticker = Ticker(handleTick);
addTearDown(ticker.dispose);
ticker.start(); ticker.start();
expect(ticker.isTicking, isTrue); expect(ticker.isTicking, isTrue);
...@@ -179,6 +182,7 @@ void main() { ...@@ -179,6 +182,7 @@ void main() {
} }
final Ticker ticker = Ticker(handleTick); final Ticker ticker = Ticker(handleTick);
addTearDown(ticker.dispose);
ticker.start(); ticker.start();
expect(tickCount, equals(0)); expect(tickCount, equals(0));
...@@ -198,4 +202,11 @@ void main() { ...@@ -198,4 +202,11 @@ void main() {
ticker.stop(); 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