Instrument more disposables. (#137309)
This commit is contained in:
parent
fea561301b
commit
65c71d4294
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user