Unverified Commit 65c71d42 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Instrument more disposables. (#137309)

parent fea56130
......@@ -246,7 +246,9 @@ class AnimationController extends Animation<double>
required TickerProvider vsync,
}) : assert(upperBound >= lowerBound),
_direction = _AnimationDirection.forward {
_maybeDispatchObjectCreation();
if (kFlutterMemoryAllocationsEnabled) {
_maybeDispatchObjectCreation();
}
_ticker = vsync.createTicker(_tick);
_internalSetValue(value ?? lowerBound);
}
......@@ -278,7 +280,9 @@ class AnimationController extends Animation<double>
}) : lowerBound = double.negativeInfinity,
upperBound = double.infinity,
_direction = _AnimationDirection.forward {
_maybeDispatchObjectCreation();
if (kFlutterMemoryAllocationsEnabled) {
_maybeDispatchObjectCreation();
}
_ticker = vsync.createTicker(_tick);
_internalSetValue(value);
}
......
......@@ -14,6 +14,8 @@ import 'framework.dart';
import 'lookup_boundary.dart';
import 'ticker_provider.dart';
const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart';
// Examples can assume:
// late BuildContext context;
......@@ -81,7 +83,11 @@ class OverlayEntry implements Listenable {
bool opaque = false,
bool maintainState = false,
}) : _opaque = opaque,
_maintainState = maintainState;
_maintainState = maintainState {
if (kFlutterMemoryAllocationsEnabled) {
_maybeDispatchObjectCreation();
}
}
/// This entry will include the widget built by this builder in the overlay at
/// the entry's position.
......@@ -140,6 +146,19 @@ class OverlayEntry implements Listenable {
/// The currently mounted `_OverlayEntryWidgetState` built using this [OverlayEntry].
ValueNotifier<_OverlayEntryWidgetState?>? _overlayEntryStateNotifier = ValueNotifier<_OverlayEntryWidgetState?>(null);
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
/// Dispatches event of object creation to [MemoryAllocations.instance].
void _maybeDispatchObjectCreation() {
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: _flutterWidgetsLibrary,
className: '$OverlayEntry',
object: this,
);
}
}
@override
void addListener(VoidCallback listener) {
assert(!_disposedByOwner);
......@@ -216,6 +235,9 @@ class OverlayEntry implements Listenable {
void dispose() {
assert(!_disposedByOwner);
assert(_overlay == null, 'An OverlayEntry must first be removed from the Overlay before dispose is called.');
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_disposedByOwner = true;
if (!mounted) {
// If we're still mounted when disposed, then this will be disposed in
......
......@@ -33,6 +33,9 @@ Future<void> testExecutable(FutureOr<void> Function() testMain) {
.withTrackedAll()
.withIgnored(
allNotGCed: true,
notDisposed: <String, int?>{
'OverlayEntry': null,
},
);
// Enable golden file testing using Skia Gold.
......
......@@ -10,6 +10,18 @@ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'semantics_tester.dart';
void main() {
test('OverlayEntry dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => OverlayEntry(
builder: (BuildContext context) => Container(),
).dispose(),
OverlayEntry,
),
areCreateAndDispose,
);
});
testWidgetsWithLeakTracking('OverflowEntries context contains Overlay', (WidgetTester tester) async {
final GlobalKey overlayKey = GlobalKey();
bool didBuild = false;
......
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